﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Text;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class AnalyticsReportDA : IAnalyticsReportDA
    {
        public DataSet GetAdjustMentRptDataSet(List<string> sqlWhere, InvAdjustmentRptQueryEntity invAdjustmentRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.ADJUSTMENT_ID AS ADJUSTMENT_ID,A.ADJUSTMENT_DATE AS ADJUSTMENT_DATE ,T.[TEXT] AS REASON_CODE,A.OWNER_ID AS OWNER_ID ,A.SKU_ID AS SKU_ID,C.SKU_CLASS_ID AS SKU_CLASS_ID,C.SKU_GROUP AS SKU_GROUP,C.DESCR AS SKU_DESCR,A.QTY AS QTY ,A.PACK_ID AS PACK_ID,D.UOM_DESCR AS UOM_DESCR,B.UNIT_PRICE AS UNIT_PRICE,(A.QTY*B.UNIT_PRICE) AS EXTENDED_PRICE,(C.NET_WGT*A.QTY) AS TOTALWGT,A.LOT AS LOT,A.LOC AS LOC,A.LPN_ID AS LPN_ID,A.REMARK AS REMARK,C.DESCR2 AS SKU_DESCR2,C.UDF2 AS SKU_UDF2,F.PRODUCE_DATE AS PRODUCE_DATE,F.EXPIRY_DATE AS EXPIRY_DATE, F.RECEIPT_DATE AS RECEIPT_DATE,F.LOT AS LOT,F.LOT_ATTR01 AS LOT_ATTR01, F.LOT_ATTR02 AS LOT_ATTR02, F.LOT_ATTR03 AS LOT_ATTR03, F.LOT_ATTR04 AS LOT_ATTR04, F.LOT_ATTR05 AS LOT_ATTR05, F.LOT_ATTR06 AS LOT_ATTR06,F.LOT_ATTR07 AS LOT_ATTR07, F.LOT_ATTR08 AS LOT_ATTR08, LAC.DESCR AS LOT_ATTR09, F.LOT_ATTR10 AS LOT_ATTR10,F.VENDOR_ID AS VENDOR_ID,F.EXTERNAL_LOT AS EXTERNAL_LOT ");
            strSql.Append(" FROM @_@ADJUSTMENT_DETAIL A  INNER JOIN @_@INV_TRANS   B  ON A.TRANS_ID=B.TRANS_ID  INNER JOIN @_@SKU C ON A.SKU_ID=C.SKU_ID AND A.OWNER_ID=C.OWNER_ID  INNER JOIN @_@UOM  D ON D.UOM_ID = A.UOM_ID  INNER JOIN @_@LOT_ATTRIBUTE F ON  A.LOT = F.LOT   LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON F.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = A.REASON_CODE AND SCD.SYS_CODE_TYPE = 'AdjReason' LEFT JOIN sysadm.TRANSLATION T ON 'AdjReason.'+A.REASON_CODE = T.ITEM_ID  AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY =@LANGUAGE  INNER JOIN SYSADM.USER_OWNER UO ON A.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID WHERE A.REASON_CODE !='UnReceive'  AND  A.REASON_CODE !='UnShipping' ");
            string sql = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            sql = (strSql.ToString() + sql).Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'").Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            if (!invAdjustmentRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, invAdjustmentRptQueryEntity.CurrentPage, invAdjustmentRptQueryEntity.PageSize, invAdjustmentRptQueryEntity.SortField, invAdjustmentRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + invAdjustmentRptQueryEntity.SortField + " " + invAdjustmentRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetASNStatusRptInfo(List<string> sqlWhere, ASNStatusRptQueryEntity asnStatusRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT RECEIPT_ID,PO_ID,T.[TEXT] AS STATUS,T2.[TEXT] AS RECEIPT_TYPE,TEMP.OWNER_ID, EXTERNAL_RECEIPT_ID,RECEIPT_DATE,EXPECTED_RECEIPT_DATE,VENDOR_ID,RMA,TEMP.REMARK,VENDOR_NAME FROM ( SELECT R.RECEIPT_ID,RD.RECEIPT_LINE_ID,R.PO_ID,R.STATUS,R.RECEIPT_TYPE,R.OWNER_ID,RD.SKU_ID,SKU.DESCR,SKU.DESCR2, SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR, R.EXTERNAL_RECEIPT_ID,R.RECEIPT_DATE,R.EXPECTED_RECEIPT_DATE,R.VENDOR_ID,R.VENDOR_NAME,R.RMA,R.REMARK FROM  @_@RECEIPT R LEFT JOIN @_@RECEIPT_DETAIL RD ON RD.RECEIPT_ID = R.RECEIPT_ID LEFT JOIN @_@SKU SKU ON RD.SKU_ID = SKU.SKU_ID AND RD.OWNER_ID = SKU.OWNER_ID LEFT JOIN @_@SKU_CLASS SC ON SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID AND SC.OWNER_ID = SKU.OWNER_ID WHERE R.IS_PALLETIZED = 'N' UNION ALL  SELECT R.RECEIPT_ID,RDL.RECEIPT_LINE_ID,R.PO_ID,R.STATUS,R.RECEIPT_TYPE,R.OWNER_ID,RDL.SKU_ID,SKU.DESCR,SKU.DESCR2, SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR, R.EXTERNAL_RECEIPT_ID,R.RECEIPT_DATE,R.EXPECTED_RECEIPT_DATE,R.VENDOR_ID,R.VENDOR_NAME,R.RMA,R.REMARK FROM  @_@RECEIPT R LEFT JOIN @_@RECEIPT_DETAIL_LPN RDL ON RDL.RECEIPT_ID = R.RECEIPT_ID LEFT JOIN @_@SKU SKU ON RDL.SKU_ID = SKU.SKU_ID AND RDL.OWNER_ID = SKU.OWNER_ID LEFT JOIN @_@SKU_CLASS SC ON SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID AND SC.OWNER_ID = SKU.OWNER_ID WHERE R.IS_PALLETIZED = 'Y' ) TEMP  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = TEMP.STATUS AND SCD.SYS_CODE_TYPE = 'ReceiptStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = TEMP.RECEIPT_TYPE AND SCD2.SYS_CODE_TYPE = 'ReceiptType' LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+TEMP.STATUS = T.ITEM_ID        AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'ReceiptType.'+TEMP.RECEIPT_TYPE = T2.ITEM_ID        AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON TEMP.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE (VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID) OR VENDOR_ID IS NULL OR VENDOR_ID = '') ";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!asnStatusRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, asnStatusRptQueryEntity.CurrentPage, asnStatusRptQueryEntity.PageSize, asnStatusRptQueryEntity.SortField, asnStatusRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + asnStatusRptQueryEntity.SortField + " " + asnStatusRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetBillingLoadDetailRptDataSet(List<string> sqlWhere, List<string> sqlWhere2, BillingLoadDetailRptQueryEntity billingLoadDetailRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            string strWhere2 = string.Empty;
            for (i = 0; i < sqlWhere2.Count; i++)
            {
                strWhere2 = strWhere2 + " AND " + sqlWhere2[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT CREDENCE_DOC_TYPE,DUE_FROM_TO,DOC_TYPE,DOC_TYPE_D,DOC_ID,EXTERNAL_DOC_ID,CONVERT(VARCHAR(20),CREATED_DATE,23) AS CREATED_DATE,COST_TYPE,COST_TYPE_D, CHARGE_UNIT, CHARGE_UNIT_D,FIXED_RATE,REMARK,IS_PRINTED,IS_HOLIDAY,WORK_TYPE,WORK_TYPE_D,WORK_CLASS,WORK_CLASS_D,FORKLIFT_DRIVER,FORKLIFT_DRIVER_D,EQUIPMENT_PROFILE_ID,EQUIPMENT_PROFILE_D, ");
            strSql.Append(" SUM(TOTAL_GROSS_WEIGHT) AS TOTAL_GROSS_WEIGHT,SUM(QUANTITY) AS QUANTITY,SUM(BILLING_AMOUNT) AS BILLING_AMOUNT ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT BC.CREDENCE_TYPE + BC.DOC_TYPE AS CREDENCE_DOC_TYPE,BC.DOC_TYPE,BC.DOC_ID,BC.EXTERNAL_DOC_ID, ");
            strSql.Append(" CASE WHEN BC.CREDENCE_TYPE = 'AccessorialCharges' AND BC.DOC_TYPE = 'InBound'  THEN '入库附加费'");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'AccessorialCharges' AND BC.DOC_TYPE = 'OutBound' THEN '出库附加费' ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'AccessorialCharges' AND BC.DOC_TYPE = 'Movement' THEN '移动附加费' ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'AccessorialCharges' AND BC.DOC_TYPE = 'VAS'      THEN '增值附加费' ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'AccessorialCharges' AND BC.DOC_TYPE = 'InvCharges' THEN '仓储附加费' ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'INBOUND' THEN T2.[TEXT] ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'OUTBOUND' THEN T2.[TEXT] ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'MOVEMENT' THEN T2.[TEXT] ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'VAS' THEN T2.[TEXT] ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'INVCHARGES' THEN T2.[TEXT] ");
            strSql.Append(" WHEN BC.CREDENCE_TYPE = 'StorageCharges' THEN T2.[TEXT] ");
            strSql.Append(" END AS DOC_TYPE_D, ");
            strSql.Append(" CASE BC.DOC_TYPE WHEN 'InBound' THEN R.CREATED_DATE WHEN 'OutBound' THEN O.CREATED_DATE WHEN 'Movement' THEN M.CREATED_DATE WHEN 'VAS' THEN ''  ELSE BC.CREATED_DATE END AS CREATED_DATE, ");
            strSql.Append(" MPR.IS_HOLIDAY,MPR.WORK_TYPE,MPR.WORK_CLASS,MPR.FORKLIFT_DRIVER,MPR.EQUIPMENT_PROFILE_ID, ");
            strSql.Append(" T1.[TEXT] AS WORK_TYPE_D,WC.DESCR AS WORK_CLASS_D,E.EMPLOYEE_NAME AS FORKLIFT_DRIVER_D,EP.DESCR AS EQUIPMENT_PROFILE_D, ");
            strSql.Append(" BC.COST_TYPE,SCD.DESCRIPTION AS COST_TYPE_D,BC.CHARGE_UNIT, T.[TEXT] AS CHARGE_UNIT_D,BC.TOTAL_GROSS_WEIGHT,BC.QUANTITY,BC.FIXED_RATE,BC.BILLING_AMOUNT,BC.REMARK,BC.DUE_FROM_TO, CASE ISNULL(BC.PRINTED_DATE,'') WHEN '' THEN 'N' ELSE 'Y' END AS IS_PRINTED ");
            strSql.Append(" FROM @_@BILLING_CREDENCE BC ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = BC.DOC_ID AND BC.DOC_TYPE = 'InBound' ");
            strSql.Append(" LEFT JOIN @_@ORDERS O ON O.ORDER_ID = BC.DOC_ID AND BC.DOC_TYPE = 'OutBound' ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT M ON M.MOVEMENT_ID = BC.DOC_ID AND BC.DOC_TYPE = 'Movement' ");
            strSql.Append(" LEFT JOIN @_@MAN_POWER_RESOURCE MPR ON MPR.ORDER_ID = BC.DOC_ID AND ((BC.DOC_TYPE = 'InBound' AND MPR.ORDER_TYPE = 'ASN') OR (BC.DOC_TYPE = 'OutBound' AND MPR.ORDER_TYPE = 'SO') OR (BC.DOC_TYPE = 'Movement' AND MPR.ORDER_TYPE = 'MV')) ");
            strSql.Append(" LEFT JOIN @_@WORK_CLASS WC ON WC.WORK_CLASS_ID = MPR.WORK_CLASS ");
            strSql.Append(" LEFT JOIN @_@EMPLOYEE E ON E.EMPLOYEE_ID = MPR.FORKLIFT_DRIVER AND E.POSITION = 'FORKLIFTDRIVER' ");
            strSql.Append(" LEFT JOIN @_@EQUIPMENT_PROFILE EP ON EP.EQUIPMENT_PROFILE_ID = MPR.EQUIPMENT_PROFILE_ID ");
            strSql.Append(" LEFT JOIN @_@SYS_CODE SC ON SC.SYS_CODE_TYPE = 'COSTTYPE' ");
            strSql.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE_TYPE = SC.SYS_CODE_TYPE AND SCD.SYS_CODE = BC.COST_TYPE ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'CHARGEUNIT.'+BC.CHARGE_UNIT = T.ITEM_ID  AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T1 ON 'WorkType.'+MPR.WORK_TYPE = T1.ITEM_ID  AND T1.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T1.LANG+'-'+T1.COUNTRY = @LANGUAGE ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T2 ON 'BillingType.'+BC.CREDENCE_TYPE = T2.ITEM_ID  AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE ");
            strSql.AppendFormat(" WHERE BC.BILLING_AMOUNT > 0 AND BC.CREDENCE_TYPE <> 'StorageCharges' {0} ", strWhere);
            strSql.Append(" ) A ");
            strSql.AppendFormat("  WHERE  1=1 {0}  ", strWhere2);
            strSql.Append(" GROUP BY CREDENCE_DOC_TYPE,DUE_FROM_TO,DOC_TYPE,DOC_TYPE_D,DOC_ID,EXTERNAL_DOC_ID,CONVERT(VARCHAR(20),CREATED_DATE,23),COST_TYPE,COST_TYPE_D,CHARGE_UNIT,CHARGE_UNIT_D,FIXED_RATE,REMARK,IS_PRINTED,IS_HOLIDAY,WORK_TYPE,WORK_CLASS_D,WORK_CLASS,WORK_TYPE_D,WORK_CLASS_D,FORKLIFT_DRIVER,FORKLIFT_DRIVER_D,EQUIPMENT_PROFILE_ID,EQUIPMENT_PROFILE_D ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!billingLoadDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), billingLoadDetailRptQueryEntity.CurrentPage, billingLoadDetailRptQueryEntity.PageSize, billingLoadDetailRptQueryEntity.SortField, billingLoadDetailRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'") + " ORDER BY " + billingLoadDetailRptQueryEntity.SortField + " " + billingLoadDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetBillingProfitRptDataSet(List<string> sqlWhere, InvoiceRptQueryEntity invoiceRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DUE_FROM_TO,DUE_FROM_TO_D,BILLING_OBJECT_ID,PREFERENCE_VALUE,COST_TYPE_D,SUM(BILLING_AMOUNT) AS BILLING_AMOUNT ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT S.DUE_FROM_TO,T1.[TEXT] AS DUE_FROM_TO_D,S.BILLING_OBJECT,S.BILLING_OBJECT_ID,S.CREATED_DATE,PPD.PREFERENCE_VALUE,CASE BC.CREDENCE_TYPE WHEN 'StorageCharges' THEN T.[TEXT] ELSE SCD.DESCRIPTION END AS COST_TYPE_D,BC.BILLING_AMOUNT ");
            strSql.Append(" FROM @_@STATEMENT S ");
            strSql.Append(" LEFT JOIN @_@STATEMENT_DETAIL SD ON SD.STATEMENT_ID = S.STATEMENT_ID ");
            strSql.Append(" LEFT JOIN @_@BILLING_CREDENCE BC ON BC.BILLING_CREDENCE_ID = SD.BILLING_CREDENCE_ID ");
            strSql.Append(" LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = S.CREATED_BY ");
            strSql.Append(" LEFT JOIN sysadm.PREFERENCE_PROFILE PP ON PP.USER_ID = UM.USER_ID ");
            strSql.Append(" LEFT JOIN sysadm.PREFERENCE_PROFILE_DETAIL PPD ON PPD.PREFERENCE_PROFILE_ID = PP.PREFERENCE_PROFILE_ID ");
            strSql.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = BC.COST_TYPE AND SCD.SYS_CODE_TYPE = 'COSTTYPE' ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'BILLINGTYPE.'+BC.CREDENCE_TYPE = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T1 ON 'DUEFROMTO.'+S.DUE_FROM_TO = T1.ITEM_ID AND T1.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T1.LANG+'-'+T1.COUNTRY = @LANGUAGE ");
            strSql.Append(" INNER JOIN sysadm.PREFERENCE P ON P.PREFERENCE_ID = PPD.PREFERENCE_ID AND P.PREFERENCE_ID = 'CURRENCY' ");
            strSql.Append(" INNER JOIN ( ");
            strSql.Append(" SELECT USER_ID,OWNER_ID AS BILLING_OBJECT_ID,'Owner' AS BILLING_OBJECT FROM SYSADM.USER_OWNER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,VENDOR_ID AS BILLING_OBJECT_ID,'Vendor' AS BILLING_OBJECT FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,CUSTOMER_ID AS BILLING_OBJECT_ID,'Customer' AS BILLING_OBJECT FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,CARRIER_ID AS BILLING_OBJECT_ID,'Carrier' AS BILLING_OBJECT FROM SYSADM.USER_CARRIER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,BILLINGENTITY_ID AS BILLING_OBJECT_ID,'BillingEntity' AS BILLING_OBJECT FROM SYSADM.USER_BILLINGENTITY WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" ) BO ON BO.BILLING_OBJECT_ID = S.BILLING_OBJECT_ID AND   BO.BILLING_OBJECT = S.BILLING_OBJECT ");
            strSql.Append(" ) A ");
            strSql.AppendFormat("  WHERE  1=1   {0}  ", strWhere);
            strSql.Append(" GROUP BY DUE_FROM_TO,DUE_FROM_TO_D,BILLING_OBJECT_ID,PREFERENCE_VALUE,COST_TYPE_D ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!invoiceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), invoiceRptQueryEntity.CurrentPage, invoiceRptQueryEntity.PageSize, invoiceRptQueryEntity.SortField, invoiceRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + invoiceRptQueryEntity.SortField + " " + invoiceRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetContractRptDataSet(List<string> sqlWhere, ContractRptQueryEntity contractRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT C.CONTRACT_ID,C.OWNER_ID,OWNER.COMPANY, T.[TEXT] AS SETTLE_ACCOUNT,PAYMENT,");
            strSql.Append(" CONVERT(VARCHAR(20),C.START_TIME,23) AS START_TIME,CONVERT(VARCHAR(20),C.END_TIME,23) AS END_TIME, ");
            strSql.Append(" @REMINDER_DAYS AS REMINDER_DAYS,DATEDIFF(day,GETDATE(),C.END_TIME) AS LAST_DAYS ");
            strSql.Append(" FROM @_@CONTRACT C ");
            strSql.Append(" LEFT JOIN @_@OWNER OWNER ON OWNER.OWNER_ID = C.OWNER_ID ");
            strSql.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = C.SETTLE_ACCOUNT AND SCD.SYS_CODE_TYPE = 'SettlementMode' ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'SettlementMode.'+C.SETTLE_ACCOUNT = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL'  AND  T.LANG+'-'+T.COUNTRY = 'zh-cn' ");
            strSql.Append(" WHERE DATEDIFF(day,GETDATE(),C.END_TIME) <= @REMINDER_DAYS ");
            strSql.AppendFormat(" {0}  ", strWhere);
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@REMINDER_DAYS", contractRptQueryEntity.ReminderDays);
            if (!contractRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, contractRptQueryEntity.CurrentPage, contractRptQueryEntity.PageSize, contractRptQueryEntity.SortField, contractRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + contractRptQueryEntity.SortField + " " + contractRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetCustomerReturnDetailRptDataSet(List<string> sqlWhere, CustomerReturnDetailRptQueryEntity customerReturnDetailRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT * FROM (  ");
            strSql.Append(" SELECT RD.RECEIPT_ID,RD.RECEIPT_LINE_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID,T.[TEXT] AS STATUS_R,RD.STATUS AS STATUS_RD,RD.RECEIVED_DATE,R.WAREHOUSE_REF,R.VENDOR_ID,R.VENDOR_NAME,RD.RECEIPT_DATE,");
            strSql.Append(" RD.SKU_ID,SKU.DESCR AS SKU_DESCR,SKU.DESCR2 AS SKU_DESCR2,RD.EXPECTED_QTY,IT.QTY AS RECEIVED_QTY,IT.HOLD_CODE AS CONDITION_CODE,IT.TO_LPN_ID,IT.LOT AS TO_LOT,LAC.DESCR AS SKU_PROPERTY, ");
            strSql.Append(" IT.LOT_ATTR01,IT.LOT_ATTR02,IT.LOT_ATTR03,IT.LOT_ATTR04,IT.LOT_ATTR05,IT.LOT_ATTR06,IT.LOT_ATTR07,IT.LOT_ATTR08,IT.LOT_ATTR09,IT.LOT_ATTR10,IT.PRODUCE_DATE,IT.EXPIRY_DATE,IT.EXTERNAL_LOT,");
            strSql.Append(" RD.REMARK,SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,SKU.SKU_GROUP,SKU.PACK_ID,SKU.UDF2 AS SKU_UDF2,RD.UNIT_PRICE,ISNULL(IT.QTY * RD.UNIT_PRICE,0) AS PRICE,");
            strSql.Append(" IT.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT,IT.QTY * SKU.[CUBE] AS TOTAL_CUBE,IT.QTY * SKU.NET_WGT AS TOTAL_WGT,U.UOM_DESCR ");
            strSql.Append(" FROM @_@RECEIPT_DETAIL RD ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID ");
            strSql.Append(" LEFT JOIN @_@INV_TRANS IT ON RD.RECEIPT_ID = IT.RECEIPT_ID AND RD.RECEIPT_LINE_ID = IT.RECEIPT_LINE_ID ");
            strSql.Append(" AND IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd'  AND IT.STATUS = 'OK' ");
            strSql.Append(" LEFT JOIN @_@VENDOR V ON IT.VENDOR_ID = V.VENDOR_ID");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID ");
            strSql.Append(" LEFT JOIN  @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID ");
            strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
            strSql.Append(" LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON IT.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            strSql.Append(" WHERE R.IS_PALLETIZED = 'N' AND R.RECEIPT_TYPE = 'Return' AND RD.[STATUS] IN ('InReceiving', 'ReceivedComplete') ");
            strSql.Append(" UNION ALL  ");
            strSql.Append(" SELECT RD.RECEIPT_ID,RD.RECEIPT_LINE_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID,T.[TEXT] AS STATUS_R,RD.STATUS AS STATUS_RD,RD.RECEIVED_DATE,R.WAREHOUSE_REF,R.VENDOR_ID,R.VENDOR_NAME,RD.RECEIPT_DATE,");
            strSql.Append(" RD.SKU_ID,SKU.DESCR AS SKU_DESCR,SKU.DESCR2 AS SKU_DESCR2,RD.EXPECTED_QTY,IT.QTY AS RECEIVED_QTY,IT.HOLD_CODE AS CONDITION_CODE,IT.TO_LPN_ID,IT.LOT AS TO_LOT,LAC.DESCR AS SKU_PROPERTY, ");
            strSql.Append(" IT.LOT_ATTR01,IT.LOT_ATTR02,IT.LOT_ATTR03,IT.LOT_ATTR04,IT.LOT_ATTR05,IT.LOT_ATTR06,IT.LOT_ATTR07,IT.LOT_ATTR08,IT.LOT_ATTR09,IT.LOT_ATTR10,IT.PRODUCE_DATE,IT.EXPIRY_DATE,IT.EXTERNAL_LOT,");
            strSql.Append(" RD.REMARK,SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,SKU.SKU_GROUP,SKU.PACK_ID,SKU.UDF2 AS SKU_UDF2,RD.UNIT_PRICE,ISNULL(IT.QTY * RD.UNIT_PRICE,0) AS PRICE,");
            strSql.Append(" IT.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT,IT.QTY * SKU.[CUBE] AS TOTAL_CUBE,IT.QTY * SKU.NET_WGT AS TOTAL_WGT,U.UOM_DESCR ");
            strSql.Append(" FROM @_@RECEIPT_DETAIL_LPN RD  ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID ");
            strSql.Append(" LEFT JOIN @_@INV_TRANS IT ON RD.RECEIPT_ID = IT.RECEIPT_ID AND RD.RECEIPT_LINE_ID = IT.RECEIPT_LINE_ID ");
            strSql.Append(" AND IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd'  AND IT.STATUS = 'OK' ");
            strSql.Append(" LEFT JOIN @_@VENDOR V ON IT.VENDOR_ID = V.VENDOR_ID");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID ");
            strSql.Append(" LEFT JOIN  @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID ");
            strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
            strSql.Append(" LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON IT.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            strSql.Append(" WHERE R.IS_PALLETIZED = 'Y' AND R.RECEIPT_TYPE = 'Return' AND RD.[STATUS] IN ('InReceiving', 'ReceivedComplete') ");
            strSql.Append(" ) TEMP WHERE (VENDOR_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR VENDOR_ID IS NULL OR VENDOR_ID = '')");
            string sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!customerReturnDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, customerReturnDetailRptQueryEntity.CurrentPage, customerReturnDetailRptQueryEntity.PageSize, customerReturnDetailRptQueryEntity.SortField, customerReturnDetailRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + customerReturnDetailRptQueryEntity.SortField + " " + customerReturnDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDailyInvPalletRptDataSet(List<string> sqlWhere, DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string sql = string.Empty;
            string strsql = string.Empty;
            string strWhere = string.Empty;
            DataSet ds = null;
            for (i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            TimeSpan startTS = new TimeSpan(Convert.ToDateTime(dailyInvPalletRptQueryEntity.StartDateTime).Ticks);
            TimeSpan endTS = new TimeSpan(Convert.ToDateTime(dailyInvPalletRptQueryEntity.EndDateTime).Ticks);
            TimeSpan diffTS = startTS.Subtract(endTS).Duration();
            if (startTS.Days > endTS.Days)
            {
                return ds;
            }
            int day = diffTS.Days;
            if (day < 0)
            {
                return ds;
            }
            sql = " SELECT CONVERT(VARCHAR(20),@DAYDATE,23) AS DAYDATE,IP.WH_ID,IP.DOC_ID,IP.DOC_TYPE,IP.OWNER_ID,O.COMPANY AS OWNER_D,IP.SKU_ID,SKU.DESCR AS SKU_D,EXEC_DATE,  CASE IP.DOC_TYPE WHEN  'SO' THEN -ISNULL(IP.[CASE],0) ELSE ISNULL(IP.[CASE],0) END AS [CASE],  CASE IP.DOC_TYPE WHEN  'SO' THEN -ISNULL(IP.[BILLING_PALLET],0) ELSE ISNULL(IP.[PALLET],0) END AS [PALLET]  FROM  @_@INV_PALLET  IP  LEFT JOIN @_@OWNER O ON O.OWNER_ID = IP.OWNER_ID  LEFT JOIN @_@SKU SKU ON SKU.SKU_ID = IP.SKU_ID AND SKU.OWNER_ID = IP.OWNER_ID  INNER JOIN SYSADM.USER_OWNER UO ON O.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID   WHERE EXEC_DATE < @DAYS ";
            for (i = 0; i <= day; i++)
            {
                strsql = strsql + sql.Replace("@DAYS", "'" + Convert.ToDateTime(dailyInvPalletRptQueryEntity.StartDateTime).AddDays((double) (i + 1)) + "'").Replace("@DAYDATE", "'" + Convert.ToDateTime(dailyInvPalletRptQueryEntity.StartDateTime).AddDays((double) i) + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + strWhere;
                if (i != day)
                {
                    strsql = strsql + " UNION ALL ";
                }
            }
            sql = (" SELECT CONVERT(VARCHAR(20),CONVERT(DATETIME,DAYDATE),23) AS DAYDATE,OWNER_ID,OWNER_D,SKU_ID,SKU_D,SUM([CASE]) AS CCASE, SUM([PALLET]) AS [PALLET]  FROM (" + strsql + " ) A GROUP BY DAYDATE,OWNER_ID,SKU_ID,OWNER_D,SKU_D").Replace("@_@", whLoginID);
            if (!dailyInvPalletRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, dailyInvPalletRptQueryEntity.CurrentPage, dailyInvPalletRptQueryEntity.PageSize, dailyInvPalletRptQueryEntity.SortField, dailyInvPalletRptQueryEntity.SortDirection);
            }
            else
            {
                string CS00004 = sql;
                sql = CS00004 + " ORDER BY " + dailyInvPalletRptQueryEntity.SortField + " " + dailyInvPalletRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDeclarationEarlyWarningRptDataSet(List<string> sqlWhere, DeclarationEarlyWarningRptQueryEntity declarationEarlyWarningRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT * FROM (");
            strSql.Append(" SELECT 1 AS SEQ_NO, '入区报关' AS [出入区类型], T_TYPE.TEXT AS DECLARATIONS_TYPE_DESCR, ID.DECLARATIONS_ID, ID.DECLARATIONS_DATE, ID.OWNER_ID, CASE ID.DECLARATIONS_TYPE WHEN 'CR' THEN ID.RECEIPT_ID WHEN 'NCR' THEN R.CORE_RELEASE_ID END AS CORE_RELEASE_ID, ID.CASE_CNT, ID.PALLET ");
            strSql.Append(" FROM WH1.IMPORT_DECLARATIONS ID ");
            strSql.Append("   LEFT JOIN SYSADM.TRANSLATION T_TYPE ON T_TYPE.TRANSLATION_ID = 'SYS_CODE_DETAIL.CustomsType.' + ID.DECLARATIONS_TYPE AND T_TYPE.LANG + '-' + T_TYPE.COUNTRY = '" + pubParasInfo.UserLanguage + "' ");
            strSql.Append("   LEFT JOIN WH1.RECEIPT R ON ID.DECLARATIONS_TYPE = 'NCR' AND R.RECEIPT_ID = ID.RECEIPT_ID ");
            strSql.Append(" WHERE ID.STATUS <> 'WrittenOff' AND DATEDIFF(DAY, ID.DECLARATIONS_DATE, GETDATE()) > " + declarationEarlyWarningRptQueryEntity.Days.ToString());
            if (!string.IsNullOrEmpty(declarationEarlyWarningRptQueryEntity.OwnerID))
            {
                strSql.Append(" AND ID.OWNER_ID " + declarationEarlyWarningRptQueryEntity.OwnerID);
            }
            strSql.Append(" UNION ");
            strSql.Append(" SELECT 2 AS SEQ_NO, '出区报关' AS [出入区类型], T_TYPE.TEXT AS DECLARATIONS_TYPE_DESCR, ED.DECLARATIONS_ID, ED.DECLARATIONS_DATE, ED.OWNER_ID, CASE ED.DECLARATIONS_TYPE WHEN 'CR' THEN ED.ORDER_ID WHEN 'NCR' THEN O.CORE_RELEASE_ID END AS CORE_RELEASE_ID, ED.CASE_CNT, ED.PALLET ");
            strSql.Append(" FROM WH1.EXPORT_DECLARATIONS ED ");
            strSql.Append("   LEFT JOIN SYSADM.TRANSLATION T_TYPE ON T_TYPE.TRANSLATION_ID = 'SYS_CODE_DETAIL.CustomsType.' + ED.DECLARATIONS_TYPE AND T_TYPE.LANG + '-' + T_TYPE.COUNTRY = '" + pubParasInfo.UserLanguage + "' ");
            strSql.Append("   LEFT JOIN WH1.ORDERS O ON ED.DECLARATIONS_TYPE = 'NCR' AND O.ORDER_ID = ED.ORDER_ID ");
            strSql.Append(" WHERE ED.STATUS <> 'WrittenOff' AND DATEDIFF(DAY, ED.DECLARATIONS_DATE, GETDATE()) > " + declarationEarlyWarningRptQueryEntity.Days.ToString());
            if (!string.IsNullOrEmpty(declarationEarlyWarningRptQueryEntity.OwnerID))
            {
                strSql.AppendFormat(" AND ED.OWNER_ID " + declarationEarlyWarningRptQueryEntity.OwnerID, new object[0]);
            }
            strSql.Append(" ) TMP");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            if (!declarationEarlyWarningRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, declarationEarlyWarningRptQueryEntity.CurrentPage, declarationEarlyWarningRptQueryEntity.PageSize, declarationEarlyWarningRptQueryEntity.SortField, declarationEarlyWarningRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + declarationEarlyWarningRptQueryEntity.SortField + " " + declarationEarlyWarningRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDeclarationsBlanaceRptDataSet(List<string> sqlWhere, DeclarationsBlanaceRptQueryEntity declarationsBlanaceRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            string strOwner = string.Empty;
            if (!string.IsNullOrEmpty(declarationsBlanaceRptQueryEntity.OwnerID))
            {
                strOwner = " and DECLARATIONS.OWNER_ID" + declarationsBlanaceRptQueryEntity.OwnerID;
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT A.OWNER_ID, A.SKU_ID, A.ITEM_NO_ID ,S.DESCR, ITEM.ITEM_NO_UOM,[ITEM].DESCR AS ITEM_NO_DESCR,P.DESCRIPTION AS PACK_ID, SUM(A.BEGINQTY) AS BEGINQTY ,SUM(A.ENDQTY) AS ENDQTY,SUM(A.INQTY) AS INQTY ,SUM(A.OTQTY) AS OTQTY ");
            strSql.Append("  FROM(  SELECT  IDD.OWNER_ID, IDD.SKU_ID, ISNULL(IDD.ITEM_NO_ID,'') AS ITEM_NO_ID ,");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE < @BEGIN_DATE  AND IDD.STATUS IN ('Audited','WrittenOff')    THEN IDD.QTY ELSE 0 END) AS BEGINQTY,   ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE <= @END_DATE AND IDD.STATUS IN ('Audited','WrittenOff')    THEN IDD.QTY ELSE 0 END) AS ENDQTY,  ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE >= @BEGIN_DATE  AND DECLARATIONS.DECLARATIONS_DATE <= @END_DATE   AND IDD.STATUS IN ('Audited','WrittenOff')  THEN IDD.QTY ELSE 0 END) AS INQTY,    ");
            strSql.Append("  0 AS OTQTY   ");
            strSql.Append("  FROM @_@IMPORT_DECLARATIONS DECLARATIONS  ");
            strSql.Append("  INNER JOIN @_@IMPORT_DECLARATIONS_DETAIL IDD ON DECLARATIONS.DECLARATIONS_ID= IDD.DECLARATIONS_ID  ");
            strSql.AppendFormat("  where  1=1 AND IDD.QTY>0   {0}  ", strOwner);
            strSql.Append("  GROUP BY  IDD.OWNER_ID, IDD.SKU_ID,IDD.ITEM_NO_ID ");
            strSql.Append("  UNION ALL ");
            strSql.Append("  SELECT  EDD.OWNER_ID, EDD.SKU_ID,  ISNULL(EDD.ITEM_NO_ID,'') AS ITEM_NO_ID  ,");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE < @BEGIN_DATE   AND EDD.STATUS IN ('Audited','WrittenOff')    THEN EDD.QTY ELSE 0 END)* -1 AS BEGINQTY, ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE <= @END_DATE AND EDD.STATUS IN ('Audited','WrittenOff')    THEN EDD.QTY ELSE 0 END)* -1 AS ENDQTY,  ");
            strSql.Append("  0 AS INQTY, ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE >= @BEGIN_DATE  AND DECLARATIONS.DECLARATIONS_DATE <= @END_DATE  AND EDD.STATUS IN ('Audited','WrittenOff')  THEN EDD.QTY ELSE 0 END) AS OTQTY    ");
            strSql.Append("  FROM @_@EXPORT_DECLARATIONS DECLARATIONS  ");
            strSql.Append("  INNER JOIN @_@EXPORT_DECLARATIONS_DETAIL EDD ON DECLARATIONS.DECLARATIONS_ID= EDD.DECLARATIONS_ID");
            strSql.AppendFormat("  where  1=1 AND EDD.QTY>0 {0}  ", strOwner);
            strSql.Append("   GROUP BY  EDD.OWNER_ID, EDD.SKU_ID,EDD.ITEM_NO_ID ");
            strSql.Append("  ) A");
            strSql.Append("  LEFT JOIN @_@SKU S ON A.SKU_ID=S.SKU_ID AND A.OWNER_ID =S.OWNER_ID");
            strSql.Append(" LEFT JOIN @_@PACK P ON S.PACK_ID=P.PACK_ID");
            strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = A.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append("  LEFT JOIN  @_@ITEM_NO ITEM ON ITEM.ITEM_NO_ID=A.ITEM_NO_ID");
            strSql.AppendFormat("  WHERE  1=1   {0}  ", strWhere);
            strSql.Append(" GROUP BY   A.OWNER_ID, A.SKU_ID, A.ITEM_NO_ID ,S.DESCR,ITEM.ITEM_NO_UOM ,[ITEM].DESCR ,P.DESCRIPTION ");
            strSql = strSql.Replace("@BEGIN_DATE", "'" + declarationsBlanaceRptQueryEntity.StartTime + "'").Replace("@END_DATE", "'" + declarationsBlanaceRptQueryEntity.EndTime + "'").Replace("@_@", whLoginID);
            if (!declarationsBlanaceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), declarationsBlanaceRptQueryEntity.CurrentPage, declarationsBlanaceRptQueryEntity.PageSize, declarationsBlanaceRptQueryEntity.SortField, declarationsBlanaceRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = string.Concat(new object[] { strSql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'"), " ORDER BY ", declarationsBlanaceRptQueryEntity.SortField, " ", declarationsBlanaceRptQueryEntity.SortDirection });
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDeclarationsInOutDetailRptDataSet(List<string> sqlWhere, DeclarationsInOutDetailRptQueryEntity declarationsInOutDetailRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT A.IN_DECLARATIONS_ID,A.COMPANY_DECLARATIONGS_ID,Convert(varchar,A.IN_DECLARATIONS_DATE) AS IN_DECLARATIONS_DATE,A.SKU_ID,A.ITEM_NO_ID,Convert(varchar,A.QTY) AS IN_QTY ,EDD.DECLARATIONS_ID AS OT_DECLARATIONS_ID,EDD.QTY AS OT_QTY, ED.DECLARATIONS_DATE AS OT_DECLARATIONS_DATE,S.DESCR AS SKU_DESCR,ITEM.DESCR AS ITEM_DESCR,ITEM.ITEM_NO_UOM AS UOM_DESCR,CONVERT(varchar,A.QTY- ISNULL(B.QTY,0)) AS RemainingQty,C.CUBE,C.GROSS_WGT,C.NET_WGT,C.UDF1,C.UDF2,C.UNIT_PRICE,C.EXTENDED_PRICE");
            strSql.Append(" FROM (  SELECT IDS.DECLARATIONS_ID AS IN_DECLARATIONS_ID ,IDS.COMPANY_DECLARATIONGS_ID,IDS.DECLARATIONS_DATE AS IN_DECLARATIONS_DATE,IDD.SKU_ID,IDD.ITEM_NO_ID,SUM(IDD.QTY) AS QTY,IDD.RECEIPT_ID,IDD.OWNER_ID ");
            strSql.Append(" FROM @_@IMPORT_DECLARATIONS IDS ");
            strSql.Append(" INNER JOIN  @_@IMPORT_DECLARATIONS_DETAIL IDD ON IDD.DECLARATIONS_ID=IDS.DECLARATIONS_ID  WHERE IDD.QTY>0 ");
            strSql.Append(" GROUP BY IDS.DECLARATIONS_ID,IDS.COMPANY_DECLARATIONGS_ID,IDS.DECLARATIONS_DATE,IDD.SKU_ID,IDD.ITEM_NO_ID,IDD.RECEIPT_ID,IDD.OWNER_ID ) A");
            strSql.Append(" LEFT JOIN @_@INV_TRANS  IT ON A.RECEIPT_ID=IT.LOT_ATTR10 AND  IT.TRANS_TYPE='OT' AND IT.SOURCE_TRANS_TYPE='PICKINGUPDATE'  AND IT.STATUS='OK'  AND  IT.SKU_ID=A.SKU_ID AND IT.OWNER_ID=A.OWNER_ID ");
            strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON IT.DOC_ID=PD.PICK_DETAIL_ID ");
            strSql.Append(" LEFT JOIN @_@ORDER_DETAIL OD ON PD.ORDER_ID=OD.ORDER_ID AND PD.ORDER_LINE_ID=OD.LINE_ID ");
            strSql.Append(" LEFT JOIN @_@EXPORT_DECLARATIONS_DETAIL EDD ON EDD.ORDER_ID =OD.ORDER_ID AND EDD.ORDER_LINE_ID=OD.LINE_ID ");
            strSql.Append(" LEFT JOIN @_@EXPORT_DECLARATIONS ED ON EDD.DECLARATIONS_ID =ED.DECLARATIONS_ID ");
            strSql.Append(" LEFT JOIN @_@SKU S ON A.OWNER_ID=S.OWNER_ID AND A.SKU_ID=S.SKU_ID");
            strSql.Append("  LEFT JOIN (SELECT SUM(EDD_GROUP.QTY) AS QTY , IDD_GROUP.DECLARATIONS_ID,IDD_GROUP.SKU_ID FROM @_@PICK_DETAIL PD_GROUP ");
            strSql.Append("  LEFT JOIN @_@EXPORT_DECLARATIONS_DETAIL EDD_GROUP ON EDD_GROUP.ORDER_ID =PD_GROUP.ORDER_ID AND EDD_GROUP.ORDER_LINE_ID=PD_GROUP.ORDER_LINE_ID ");
            strSql.Append("  LEFT JOIN @_@LOT_ATTRIBUTE L_GROUP ON L_GROUP.LOT=PD_GROUP.LOT ");
            strSql.Append("  LEFT JOIN @_@IMPORT_DECLARATIONS_DETAIL IDD_GROUP ON  L_GROUP.LOT_ATTR10 =IDD_GROUP.RECEIPT_ID AND IDD_GROUP.SKU_ID =L_GROUP.SKU_ID ");
            strSql.Append("   GROUP BY IDD_GROUP.DECLARATIONS_ID,IDD_GROUP.SKU_ID ) B ON B.DECLARATIONS_ID =A.IN_DECLARATIONS_ID   AND B.SKU_ID=A.SKU_ID ");
            strSql.Append(" LEFT JOIN @_@ITEM_NO ITEM ON ITEM.ITEM_NO_ID=A.ITEM_NO_ID ");
            strSql.Append(" LEFT JOIN (SELECT DECLARATIONS_ID,SKU_ID,SUM(CUBE) AS CUBE,SUM(GROSS_WGT) AS GROSS_WGT ,SUM(NET_WGT) AS NET_WGT,SUM(CONVERT(float,ISNULL(UDF1,'0'))) AS UDF1,SUM(CONVERT(float,ISNULL(UDF2,'0'))) AS UDF2,UNIT_PRICE,SUM(EXTENDED_PRICE) AS EXTENDED_PRICE FROM @_@EXPORT_DECLARATIONS_DETAIL SUM_EDD GROUP BY DECLARATIONS_ID,SKU_ID,UNIT_PRICE) C");
            strSql.Append(" ON  EDD.DECLARATIONS_ID = C.DECLARATIONS_ID AND EDD.SKU_ID=C.SKU_ID ");
            strSql = strSql.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    strSql.AppendFormat(" WHERE {0} ", sqlWhere[i].ToString());
                }
                else
                {
                    strSql.AppendFormat(" AND {0} ", sqlWhere[i].ToString());
                }
            }
            if (!declarationsInOutDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), declarationsInOutDetailRptQueryEntity.CurrentPage, declarationsInOutDetailRptQueryEntity.PageSize, declarationsInOutDetailRptQueryEntity.SortField, declarationsInOutDetailRptQueryEntity.SortDirection);
            }
            else
            {
                sql = strSql.ToString() + " ORDER BY " + declarationsInOutDetailRptQueryEntity.SortField + " " + declarationsInOutDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDeclarationsItemNoBlanaceRptDataSet(List<string> sqlWhere, DeclarationsItemNoBlanaceRptQueryEntity declarationsItemNoBlanaceRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT A.ITEM_NO_ID ,ITEM.DESCR AS ITEM_NO_DESCR , ITEM.ITEM_NO_UOM , SUM(A.BEGINQTY) AS BEGINQTY ,SUM(A.ENDQTY) AS ENDQTY,SUM(A.INQTY) AS INQTY ,SUM(A.OTQTY) AS OTQTY   ");
            strSql.Append("  FROM( SELECT  IDD.OWNER_ID,ISNULL(IDD.ITEM_NO_ID,'') AS ITEM_NO_ID , IDD.UOM_ID  , SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE < @BEGIN_DATE AND IDD.STATUS IN ('Audited','WrittenOff')    THEN IDD.QTY ELSE 0 END) AS BEGINQTY,     ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE <= @END_DATE AND IDD.STATUS IN ('Audited','WrittenOff')    THEN IDD.QTY ELSE 0 END) AS ENDQTY, SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE >= @BEGIN_DATE AND DECLARATIONS.DECLARATIONS_DATE <= @END_DATE   ");
            strSql.Append("  AND IDD.STATUS IN ('Audited','WrittenOff')  THEN IDD.QTY ELSE 0 END) AS INQTY, 0 AS OTQTY   ");
            strSql.Append("  FROM @_@IMPORT_DECLARATIONS DECLARATIONS INNER JOIN @_@IMPORT_DECLARATIONS_DETAIL IDD ON DECLARATIONS.DECLARATIONS_ID= IDD.DECLARATIONS_ID ");
            strSql.Append("  where  1=1 AND IDD.QTY>0 ");
            strSql.Append("  GROUP BY IDD.OWNER_ID, IDD.ITEM_NO_ID , IDD.UOM_ID ");
            strSql.Append("  UNION ALL  ");
            strSql.Append("  SELECT  EDD.OWNER_ID , ISNULL(EDD.ITEM_NO_ID,'') AS ITEM_NO_ID , EDD.UOM_ID , SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE < @BEGIN_DATE AND EDD.STATUS IN ('Audited','WrittenOff')    THEN EDD.QTY ELSE 0 END)* -1 AS BEGINQTY,   ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE <= @END_DATE AND EDD.STATUS IN ('Audited','WrittenOff')    THEN EDD.QTY ELSE 0 END)* -1 AS ENDQTY, 0 AS INQTY,    ");
            strSql.Append("  SUM(CASE WHEN DECLARATIONS.DECLARATIONS_DATE >= @BEGIN_DATE AND DECLARATIONS.DECLARATIONS_DATE <= @END_DATE AND EDD.STATUS IN ('Audited','WrittenOff')  THEN EDD.QTY ELSE 0 END) AS OTQTY    ");
            strSql.Append("  FROM @_@EXPORT_DECLARATIONS DECLARATIONS INNER JOIN @_@EXPORT_DECLARATIONS_DETAIL EDD ON DECLARATIONS.DECLARATIONS_ID= EDD.DECLARATIONS_ID  ");
            strSql.Append("  where  1=1 AND EDD.QTY>0  ");
            strSql.Append("  GROUP BY EDD.OWNER_ID, EDD.ITEM_NO_ID , EDD.UOM_ID ");
            strSql.Append("  ) A  ");
            strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = A.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append("  LEFT JOIN  @_@ITEM_NO ITEM ON ITEM.ITEM_NO_ID=A.ITEM_NO_ID ");
            strSql.AppendFormat("  WHERE  1=1   {0}  ", strWhere);
            strSql.Append("  GROUP BY  A.ITEM_NO_ID,ITEM.DESCR , ITEM.ITEM_NO_UOM ");
            strSql = strSql.Replace("@BEGIN_DATE", "'" + declarationsItemNoBlanaceRptQueryEntity.StartTime + "'").Replace("@END_DATE", "'" + declarationsItemNoBlanaceRptQueryEntity.EndTime + "'").Replace("@_@", whLoginID);
            if (!declarationsItemNoBlanaceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), declarationsItemNoBlanaceRptQueryEntity.CurrentPage, declarationsItemNoBlanaceRptQueryEntity.PageSize, declarationsItemNoBlanaceRptQueryEntity.SortField, declarationsItemNoBlanaceRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = string.Concat(new object[] { strSql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'"), " ORDER BY ", declarationsItemNoBlanaceRptQueryEntity.SortField, " ", declarationsItemNoBlanaceRptQueryEntity.SortDirection });
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDeliveryOrderRptDataSet(List<string> sqlWhere, DeliveryOrderRptQueryEntity deliveryOrderRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT * FROM (");
            strSql.Append(" SELECT DO.DELIVERY_ORDER_ID, DO.CREATED_DATE, DO.EXTERN_ORDER_ID, DO.EXTERN_ORDER_ID2, ");
            strSql.Append("   DO.DELIVERY_LOC_ID, DO.OWNER_ID, DO.CUSTOMER_ID, DO.TOTAL_QTY, DO.TOTAL_WEIGHT, DO.TOTAL_CUBE, ");
            strSql.Append("   DO.FREIGHT, DO.TAKE_FEE, DO.AMOUNT, DO.RECEIPTED, DO.REMARK, POD.SIGNED_DATE, POD.EQUIPMENT_ID ");
            strSql.Append(" FROM @_@DELIVERY_ORDER DO ");
            strSql.Append("   LEFT JOIN @_@POD POD ON POD.DELIVERY_ID = DO.DELIVERY_ORDER_ID ");
            strSql.Append(" WHERE 1 = 1 ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" ) TMP");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            if (!deliveryOrderRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, deliveryOrderRptQueryEntity.CurrentPage, deliveryOrderRptQueryEntity.PageSize, deliveryOrderRptQueryEntity.SortField, deliveryOrderRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + deliveryOrderRptQueryEntity.SortField + " " + deliveryOrderRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetDiffCountReportList(List<string> sqlWhere, DiffCountRptQueryEntity diffCountRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT tmp.LOC, tmp.OWNER_ID, tmp.SKU_ID, tmp.SKU_DESCR, tmp.SKU_DESCR2, tmp.SKU_STYLE, tmp.UOM_ID, tmp.LPN_ID, SUM(INV_QTY) AS INV_QTY ");
            if (diffCountRptQueryEntity.ShowLot == "Y")
            {
                strSql.Append(" , LOT, EXTERNAL_LOT, PRODUCE_DATE, EXPIRY_DATE, VENDOR_ID, RECEIPT_DATE, LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10");
            }
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT DISTINCT ILLL.LOC, ILLL.OWNER_ID, ILLL.SKU_ID, ILLL.LPN_ID, ILLL.LOT, ILLL.QTY AS INV_QTY, S.DESCR AS SKU_DESCR,S.DESCR2 AS SKU_DESCR2, P.PACK_ID AS SKU_STYLE, U.UOM_DESCR AS UOM_ID, LA.EXTERNAL_LOT, LA.PRODUCE_DATE, LA.EXPIRY_DATE,LA.VENDOR_ID, LA.RECEIPT_DATE, LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05,LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LAC.DESCR AS LOT_ATTR09, LA.LOT_ATTR10 ");
            strSql.Append(" FROM @_@INV_LOT_LOC_LPN ILLL ");
            strSql.Append(" LEFT JOIN @_@LOCATION L ON ILLL.LOC=L.LOC ");
            strSql.Append(" LEFT JOIN @_@SKU S ON S.OWNER_ID = ILLL.OWNER_ID AND S.SKU_ID = ILLL.SKU_ID ");
            strSql.Append(" LEFT JOIN @_@PACK P ON P.PACK_ID = S.PACK_ID ");
            strSql.Append(" LEFT JOIN @_@UOM U ON P.PACK_UOM1=U.UOM_ID ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = ILLL.LOT ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            if (!string.IsNullOrEmpty(diffCountRptQueryEntity.OrderID))
            {
                strSql.AppendFormat(" INNER JOIN (SELECT DISTINCT PD.LOC FROM @_@PICK_DETAIL PD WHERE PD.STATUS = 'SHIPPED' AND PD.ORDER_ID {0}) PD ON PD.LOC = L.LOC", diffCountRptQueryEntity.OrderID);
            }
            if (diffCountRptQueryEntity.ShowOtherSku == "Y")
            {
                strSql.AppendFormat(" WHERE ( ILLL.LOC IN (SELECT DISTINCT FROM_LOC FROM @_@INV_TRANS IT WHERE IT.TRANS_DATE BETWEEN '{0}' AND '{1}' ) OR ILLL.LOC IN (SELECT DISTINCT TO_LOC FROM @_@INV_TRANS IT WHERE IT.TRANS_DATE BETWEEN '{0}' AND '{1}'))", diffCountRptQueryEntity.StartTime, diffCountRptQueryEntity.EndTime);
            }
            else
            {
                strSql.AppendFormat(" WHERE ( ILLL.LOC IN (SELECT DISTINCT FROM_LOC FROM @_@INV_TRANS IT WHERE IT.TRANS_DATE BETWEEN '{0}' AND '{1}'AND ILLL.OWNER_ID =IT.OWNER_ID AND ILLL.SKU_ID=IT.SKU_ID  ) OR ILLL.LOC IN (SELECT DISTINCT TO_LOC FROM @_@INV_TRANS IT WHERE IT.TRANS_DATE BETWEEN '{0}' AND '{1}' AND ILLL.OWNER_ID =IT.OWNER_ID AND ILLL.SKU_ID=IT.SKU_ID))", diffCountRptQueryEntity.StartTime, diffCountRptQueryEntity.EndTime);
            }
            strSql.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" ) tmp ");
            strSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON tmp.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID");
            strSql.Append(" GROUP BY tmp.LOC, tmp.OWNER_ID, tmp.SKU_ID, tmp.SKU_DESCR, tmp.SKU_DESCR2, tmp.SKU_STYLE, tmp.UOM_ID, tmp.LPN_ID ");
            if (diffCountRptQueryEntity.ShowLot == "Y")
            {
                strSql.Append(" , LOT, EXTERNAL_LOT, PRODUCE_DATE, EXPIRY_DATE, VENDOR_ID, RECEIPT_DATE, LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10");
            }
            string sql = strSql.ToString();
            if (!diffCountRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, diffCountRptQueryEntity.CurrentPage, diffCountRptQueryEntity.PageSize, diffCountRptQueryEntity.SortField, diffCountRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + diffCountRptQueryEntity.SortField + " " + diffCountRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetEmployeeWorkRptDataSet(List<string> sqlWhere, EmployeeWorkRptQueryEntity employeeWorkRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT  A.STORE_MAN,A.EMPLOYEE_NAME,SUM(A.INCOUNT) AS INCOUNT,SUM(A.OUTCOUNT)  AS OUTCOUNT,SUM(A.MVCOUNT) AS MVCOUNT, ");
            strSql.Append(" SUM(A.INCOUNT+A.OUTCOUNT+A.MVCOUNT) AS TOTAL_ORDER_COUNT,SUM(A.RECEIVED_QTY + A.SHIPPED_QTY + A.MOVE_QTY) AS TOTAL_QTY, ");
            strSql.Append(" SUM(A.TOTAL_CUBE) AS TOTAL_CUBE,SUM(A.TOTAL_GROSS_WEIGHT)  AS TOTAL_GROSS_WEIGHT ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT 'IN' AS TYPE,MPR.STORE_MAN,E.EMPLOYEE_NAME,COUNT(DISTINCT MPR.ORDER_ID) AS INCOUNT,SUM(RD.RECEIVED_QTY) AS RECEIVED_QTY, ");
            strSql.Append("  0 AS OUTCOUNT,0 AS SHIPPED_QTY,0 AS MVCOUNT,0 AS MOVE_QTY, ");
            strSql.Append(" SUM(RD.RECEIVED_QTY*SKU.CUBE) AS TOTAL_CUBE,SUM(RD.RECEIVED_QTY*SKU.GROSS_WGT) AS TOTAL_GROSS_WEIGHT ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR  ");
            strSql.Append(" LEFT JOIN @_@EMPLOYEE E ON E.EMPLOYEE_ID = MPR.STORE_MAN ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@RECEIPT_DETAIL RD ON RD.RECEIPT_ID = R.RECEIPT_ID ");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.SKU_ID = RD.SKU_ID AND SKU.OWNER_ID = RD.OWNER_ID ");
            strSql.Append(" WHERE ISNULL(MPR.STORE_MAN,'') <> '' AND MPR.ORDER_TYPE = 'ASN' ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY MPR.STORE_MAN,E.EMPLOYEE_NAME ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'OT' AS TYPE,MPR.STORE_MAN,E.EMPLOYEE_NAME,0 AS INCOUNT,0 AS RECEIVED_QTY, ");
            strSql.Append(" COUNT(DISTINCT MPR.ORDER_ID) AS OUTCOUNT,SUM(OD.SHIPPED_QTY) AS SHIPPED_QTY, 0 AS MVCOUNT,0 AS MOVE_QTY, ");
            strSql.Append(" SUM(OD.SHIPPED_QTY*SKU.CUBE) AS TOTAL_CUBE,SUM(OD.SHIPPED_QTY*SKU.GROSS_WGT) AS TOTAL_GROSS_WEIGHT ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@EMPLOYEE E ON E.EMPLOYEE_ID = MPR.STORE_MAN ");
            strSql.Append(" LEFT JOIN @_@ORDERS O ON O.ORDER_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@ORDER_DETAIL OD ON OD.ORDER_ID = O.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.SKU_ID = OD.SKU_ID AND SKU.OWNER_ID = OD.OWNER_ID ");
            strSql.Append(" WHERE ISNULL(MPR.STORE_MAN,'') <> '' AND  MPR.ORDER_TYPE = 'SO' ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY MPR.STORE_MAN,E.EMPLOYEE_NAME ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'MV' AS TYPE,MPR.STORE_MAN,E.EMPLOYEE_NAME,0 AS INCOUNT,0 AS RECEIVED_QTY, ");
            strSql.Append(" 0 AS OUTCOUNT,0 AS SHIPPED_QTY, COUNT(DISTINCT MPR.ORDER_ID) AS MVCOUNT,SUM(MD.QTY) AS MOVE_QTY, ");
            strSql.Append(" SUM(MD.QTY*SKU.CUBE) AS TOTAL_CUBE,SUM(MD.QTY*SKU.GROSS_WGT) AS TOTAL_GROSS_WEIGHT ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@EMPLOYEE E ON E.EMPLOYEE_ID = MPR.STORE_MAN ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT M ON M.MOVEMENT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT_DETAIL MD ON MD.MOVEMENT_ID = M.MOVEMENT_ID ");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.SKU_ID = MD.SKU_ID AND SKU.OWNER_ID = MD.OWNER_ID ");
            strSql.Append(" WHERE ISNULL(MPR.STORE_MAN,'') <> '' AND  MPR.ORDER_TYPE = 'MV' ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY MPR.STORE_MAN,E.EMPLOYEE_NAME ");
            strSql.Append(" ) A GROUP BY A.STORE_MAN,A.EMPLOYEE_NAME ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!employeeWorkRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), employeeWorkRptQueryEntity.CurrentPage, employeeWorkRptQueryEntity.PageSize, employeeWorkRptQueryEntity.SortField, employeeWorkRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + employeeWorkRptQueryEntity.SortField + " " + employeeWorkRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetEmptyLocationRptInfo(List<string> sqlWhere, EmptyLocationRptQueryEntity emptyLocationRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            sql = "SELECT DISTINCT * FROM (  SELECT LOC.LOC,LOC.ZONE_ID,  LOC.LOC_USAGE,  T.[TEXT] AS T_LOC_USAGE,  LOC.ABC,  T3.[TEXT] AS T_ABC,  LOC.STATUS,  T2.[TEXT] AS T_STATUS,  LOC.LOC_FLAG,  T1.[TEXT] AS T_LOC_FLAG,  LOC.LOGICAL_LOC,LOC.IS_MULTI_SKU,LOC.IS_MULTI_LOT,LOC.CHECK_DIG,LOC.CUBIC_CAPACITY,LOC.WEIGHT_CAPACITY   FROM @_@LOCATION as LOC  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = LOC.LOC_USAGE AND SCD.SYS_CODE_TYPE = 'LocUsage'  LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = LOC.LOC_FLAG AND SCD2.SYS_CODE_TYPE = 'LocFlag'  LEFT JOIN @_@SYS_CODE_DETAIL SCD3 ON SCD3.SYS_CODE = LOC.STATUS AND SCD3.SYS_CODE_TYPE = 'LocFlag'  LEFT JOIN @_@SYS_CODE_DETAIL SCD4 ON SCD4.SYS_CODE = LOC.ABC AND SCD3.SYS_CODE_TYPE = 'ABC'  LEFT JOIN sysadm.TRANSLATION T ON 'LocUsage.'+ LOC.LOC_USAGE = T.ITEM_ID         AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE   LEFT JOIN sysadm.TRANSLATION T1 ON 'LocFlag.'+LOC.LOC_FLAG = T1.ITEM_ID     AND  T1.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T1.LANG+'-'+T1.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T2 ON 'LocFlag.'+LOC.STATUS = T2.ITEM_ID    AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T3 ON 'ABC.'+LOC.ABC = T3.ITEM_ID     AND  T3.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T3.LANG+'-'+T3.COUNTRY = @LANGUAGE  WHERE LOC.LOC NOT IN (SELECT LOC FROM @_@INV_SKU_LOC)   ) TEMP  ";
            sql = sql.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!emptyLocationRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, emptyLocationRptQuery.CurrentPage, emptyLocationRptQuery.PageSize, emptyLocationRptQuery.SortField, emptyLocationRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + emptyLocationRptQuery.SortField + " " + emptyLocationRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetExportDeclarationsRptDateSet(List<string> sqlWhere, ExportDeclarationsRptQueryEntity exportDeclarationsRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT EDS.DECLARATIONS_DATE,EDS.DECLARATIONS_ID,EDS.COMPANY_DECLARATIONGS_ID,EDS.VERIFICATION_FORM_ID,EDS.OWNER_ID,EDS.OWNER_ORDER_ID,EDD.SKU_ID,INO.ITEM_NO_UOM,SUM(EDD.QTY) AS QTY,EDD.UNIT_PRICE,S.DESCR AS SKU_DESCR,EDD.ITEM_NO_ID,INO.DESCR AS ITEM_NO_DESCR,SUM(EDD.[CUBE]) AS [CUBE],SUM(EDD.GROSS_WGT) AS GROSS_WGT,SUM(EDD.NET_WGT) AS NET_WGT,SUM(EDD.EXTENDED_PRICE) AS EXTENDED_PRICE,SUM(CONVERT(FLOAT,ISNULL(EDD.UDF1,'0'))) AS UDF1,SUM(CONVERT(FLOAT,ISNULL(EDD.UDF2,'0'))) AS UDF2  ");
            strSql.Append(" FROM @_@EXPORT_DECLARATIONS EDS LEFT JOIN @_@EXPORT_DECLARATIONS_DETAIL EDD ON EDS.DECLARATIONS_ID=EDD.DECLARATIONS_ID ");
            strSql.Append(" LEFT JOIN @_@SKU S ON EDD.OWNER_ID=S.OWNER_ID AND EDD.SKU_ID = S.SKU_ID ");
            strSql.Append(" LEFT JOIN @_@ITEM_NO INO ON EDD.ITEM_NO_ID=INO.ITEM_NO_ID ");
            strSql = strSql.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    strSql.AppendFormat(" WHERE {0} ", sqlWhere[i].ToString());
                }
                else
                {
                    strSql.AppendFormat(" AND {0} ", sqlWhere[i].ToString());
                }
            }
            strSql.Append(" GROUP BY EDS.DECLARATIONS_DATE,EDS.DECLARATIONS_ID,EDS.COMPANY_DECLARATIONGS_ID,EDS.VERIFICATION_FORM_ID,EDS.OWNER_ID,EDS.OWNER_ORDER_ID,EDD.SKU_ID,INO.ITEM_NO_UOM,EDD.UNIT_PRICE,S.DESCR ,EDD.ITEM_NO_ID,INO.DESCR ");
            if (!exportDeclarationsRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), exportDeclarationsRptQueryEntity.CurrentPage, exportDeclarationsRptQueryEntity.PageSize, exportDeclarationsRptQueryEntity.SortField, exportDeclarationsRptQueryEntity.SortDirection);
            }
            else
            {
                sql = strSql.ToString() + " ORDER BY " + exportDeclarationsRptQueryEntity.SortField + " " + exportDeclarationsRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetFinanceInOutStockDetailRptDataSet(List<string> sqlWhere, FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            if (financeInOutStockDetailRptQueryEntity.ShowLot == "Y")
            {
                sql = "SELECT DISTINCT IL.OWNER_ID,IL.SKU_ID,SKU.DESCR,SKU.DESCR2,SKU.UDF2 AS SKU_UDF2,SKU.SKU_GROUP,UOM.UOM_DESCR,SC.DESCR AS SKU_CLASS_DESCR, ISNULL(IL.UNIT_PRICE,0) AS UNIT_PRICE,ISNULL(INIT.INIT_QTY,0) AS INIT_QTY, ISNULL(IL.UNIT_PRICE,0) AS INIT_PRICE,ISNULL(IL.UNIT_PRICE,0)*ISNULL(INIT.INIT_QTY,0) AS INIT_AMOUNT,  ISNULL(IB.IN_QTY,0) AS IN_QTY,ISNULL(IB.IN_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS IN_AMOUNT, ISNULL(OB.OUT_QTY,0) AS OUT_QTY,ISNULL(OB.OUT_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS OUT_AMOUNT, ISNULL(AJ.AJ_QTY,0) AS AJ_QTY,ISNULL(AJ.AJ_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS AJ_AMOUNT,  (ISNULL(INIT.INIT_QTY,0) + ISNULL(IB.IN_QTY,0) - ISNULL(OB.OUT_QTY,0) + ISNULL(AJ.AJ_QTY,0)) AS END_QTY, ISNULL(IL.UNIT_PRICE,0) AS END_PRICE,(ISNULL(INIT.INIT_QTY,0) + ISNULL(IB.IN_QTY,0) - ISNULL(OB.OUT_QTY,0) + ISNULL(AJ.AJ_QTY,0))*ISNULL(IL.UNIT_PRICE,0) AS END_AMOUNT,  LA.EXTERNAL_LOT,LA.VENDOR_ID,LA.PRODUCE_DATE,LA.EXPIRY_DATE,LA.RECEIPT_DATE,LA.LOT_ATTR01,LA.LOT_ATTR02,LA.LOT_ATTR03,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06,LA.LOT_ATTR07,LA.LOT_ATTR08, LA.LOT_ATTR09,LA.LOT_ATTR10 FROM @_@INV_LOT IL  LEFT JOIN ( SELECT IT1.OWNER_ID, IT1.SKU_ID, IT1.LOT,SUM(IT1.QTY) - ABS(ISNULL(IT2.QTY,0)) + ISNULL(IT_AJ.QTY,0) AS INIT_QTY FROM @_@INV_TRANS IT1 FULL JOIN ( SELECT OWNER_ID,SKU_ID,LOT,SUM(QTY) AS QTY FROM @_@INV_TRANS WHERE TRANS_TYPE = 'OT' AND SOURCE_TRANS_TYPE = 'PICKINGUPDATE' AND STATUS = 'OK' AND TRANS_DATE < @BEGIN_DATE GROUP BY OWNER_ID,SKU_ID,LOT ) IT2 ON IT1.OWNER_ID = IT2.OWNER_ID AND IT1.SKU_ID = IT2.SKU_ID AND IT1.LOT = IT2.LOT FULL JOIN ( SELECT OWNER_ID,SKU_ID,LOT,SUM(QTY) AS QTY FROM @_@INV_TRANS WHERE TRANS_TYPE IN ('AJ','MV') AND SOURCE_TRANS_TYPE IN ('AdjustmentDetailAdd','CycleCountAdd','TransferDetailAdd','TransferDetailUpdate') AND STATUS = 'OK' AND TRANS_DATE < @BEGIN_DATE GROUP BY OWNER_ID,SKU_ID,LOT ) IT_AJ ON IT1.OWNER_ID = IT_AJ.OWNER_ID AND IT1.SKU_ID = IT_AJ.SKU_ID AND IT1.LOT = IT_AJ.LOT WHERE IT1.TRANS_TYPE = 'IN' AND IT1.SOURCE_TRANS_TYPE = 'RECEIPTDETAILADD' AND IT1.STATUS = 'OK' AND RECEIPT_DATE < @BEGIN_DATE GROUP BY IT1.OWNER_ID, IT1.SKU_ID,IT1.LOT,IT2.QTY,IT_AJ.QTY ) INIT ON IL.OWNER_ID = INIT.OWNER_ID AND IL.SKU_ID = INIT.SKU_ID AND INIT.LOT = IL.LOT LEFT JOIN  ( SELECT IT.OWNER_ID,IT.SKU_ID,IT.LOT,SUM(IT.QTY) AS IN_QTY FROM @_@INV_TRANS IT LEFT JOIN @_@RECEIPT R ON IT.DOC_ID = R.RECEIPT_ID WHERE IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'RECEIPTDETAILADD' AND IT.STATUS = 'OK' AND IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.LOT  ) IB ON IL.OWNER_ID = IB.OWNER_ID AND IL.SKU_ID = IB.SKU_ID AND IL.LOT= IB.LOT LEFT JOIN ( SELECT IT.OWNER_ID,IT.SKU_ID,IT.LOT,ABS(SUM(IT.QTY)) AS OUT_QTY FROM @_@INV_TRANS IT LEFT JOIN @_@ORDERS O ON IT.DOC_ID = O.ORDER_ID WHERE IT.TRANS_TYPE = 'OT' AND IT.SOURCE_TRANS_TYPE = 'PICKINGUPDATE' AND IT.STATUS = 'OK' AND IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.LOT ) OB ON IL.OWNER_ID = OB.OWNER_ID AND IL.SKU_ID = OB.SKU_ID AND IL.LOT = OB.LOT LEFT JOIN (  SELECT IT.OWNER_ID,IT.SKU_ID,IT.LOT,SUM(IT.QTY) AS AJ_QTY   FROM @_@INV_TRANS IT  WHERE IT.[STATUS] = 'OK' AND IT.TRANS_TYPE IN ('AJ','MV') AND IT.SOURCE_TRANS_TYPE IN ('AdjustmentDetailAdd','CycleCountAdd','TransferDetailAdd','TransferDetailUpdate')  AND IT.TRANS_DATE BETWEEN @BEGIN_DATE AND @END_DATE  GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.LOT  ) AJ ON IL.OWNER_ID = AJ.OWNER_ID AND IL.SKU_ID = AJ.SKU_ID AND IL.LOT = AJ.LOT  LEFT JOIN @_@SKU SKU ON IL.OWNER_ID = SKU.OWNER_ID AND IL.SKU_ID = SKU.SKU_ID  LEFT JOIN @_@SKU_CLASS SC ON SKU.OWNER_ID = SC.OWNER_ID AND SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID  LEFT JOIN @_@PACK P ON SKU.PACK_ID = P.PACK_ID  LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1  LEFT JOIN @_@LOT_ATTRIBUTE LA  ON IL.LOT = LA.LOT INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = IL.OWNER_ID AND UO.[USER_ID] = @USER_ID ";
            }
            else
            {
                sql = "SELECT DISTINCT IL.OWNER_ID,IL.SKU_ID,SKU.DESCR,SKU.DESCR2,SKU.UDF2 AS SKU_UDF2,SKU.SKU_GROUP,UOM.UOM_DESCR,SC.DESCR AS SKU_CLASS_DESCR, ISNULL(IL.UNIT_PRICE,0) AS UNIT_PRICE,ISNULL(INIT.INIT_QTY,0) AS INIT_QTY, ISNULL(IL.UNIT_PRICE,0) AS INIT_PRICE,ISNULL(IL.UNIT_PRICE,0)*ISNULL(INIT.INIT_QTY,0) AS INIT_AMOUNT,  ISNULL(IB.IN_QTY,0) AS IN_QTY,ISNULL(IB.IN_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS IN_AMOUNT, ISNULL(OB.OUT_QTY,0) AS OUT_QTY,ISNULL(OB.OUT_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS OUT_AMOUNT, ISNULL(AJ.AJ_QTY,0) AS AJ_QTY,ISNULL(AJ.AJ_QTY,0)*ISNULL(IL.UNIT_PRICE,0) AS AJ_AMOUNT,  (ISNULL(INIT.INIT_QTY,0) + ISNULL(IB.IN_QTY,0) - ISNULL(OB.OUT_QTY,0) + ISNULL(AJ.AJ_QTY,0)) AS END_QTY, ISNULL(IL.UNIT_PRICE,0) AS END_PRICE,(ISNULL(INIT.INIT_QTY,0) + ISNULL(IB.IN_QTY,0) - ISNULL(OB.OUT_QTY,0) + ISNULL(AJ.AJ_QTY,0))*ISNULL(IL.UNIT_PRICE,0) AS END_AMOUNT  FROM @_@INV_LOT IL  LEFT JOIN  ( SELECT IT1.OWNER_ID, IT1.SKU_ID, IT1.UNIT_PRICE,SUM(IT1.QTY) - ABS(ISNULL(IT2.QTY,0)) + ISNULL(IT_AJ.QTY,0) AS INIT_QTY FROM @_@INV_TRANS IT1 FULL JOIN ( SELECT OWNER_ID,SKU_ID,UNIT_PRICE,SUM(QTY) AS QTY FROM @_@INV_TRANS WHERE TRANS_TYPE = 'OT' AND SOURCE_TRANS_TYPE = 'PICKINGUPDATE' AND STATUS = 'OK' AND TRANS_DATE < @BEGIN_DATE GROUP BY OWNER_ID,SKU_ID,UNIT_PRICE ) IT2 ON IT1.OWNER_ID = IT2.OWNER_ID AND IT1.SKU_ID = IT2.SKU_ID AND IT1.UNIT_PRICE = IT2.UNIT_PRICE FULL JOIN ( SELECT OWNER_ID,SKU_ID,UNIT_PRICE,SUM(QTY) AS QTY FROM @_@INV_TRANS WHERE TRANS_TYPE IN ('AJ','MV') AND SOURCE_TRANS_TYPE IN ('AdjustmentDetailAdd','CycleCountAdd','TransferDetailAdd','TransferDetailUpdate') AND STATUS = 'OK' AND TRANS_DATE < @BEGIN_DATE GROUP BY OWNER_ID,SKU_ID,UNIT_PRICE ) IT_AJ ON IT1.OWNER_ID = IT_AJ.OWNER_ID AND IT1.SKU_ID = IT_AJ.SKU_ID AND IT1.UNIT_PRICE = IT_AJ.UNIT_PRICE WHERE IT1.TRANS_TYPE = 'IN' AND IT1.SOURCE_TRANS_TYPE = 'RECEIPTDETAILADD' AND IT1.STATUS = 'OK' AND RECEIPT_DATE < @BEGIN_DATE GROUP BY IT1.OWNER_ID, IT1.SKU_ID,IT1.UNIT_PRICE,IT2.QTY,IT_AJ.QTY ) INIT ON IL.OWNER_ID = INIT.OWNER_ID AND IL.SKU_ID = INIT.SKU_ID AND IL.UNIT_PRICE = INIT.UNIT_PRICE LEFT JOIN  ( SELECT IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE,SUM(IT.QTY) AS IN_QTY FROM @_@INV_TRANS IT LEFT JOIN @_@RECEIPT R ON IT.DOC_ID = R.RECEIPT_ID WHERE IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'RECEIPTDETAILADD' AND IT.STATUS = 'OK' AND R.RECEIPT_TYPE <> 'RETURN' AND IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE ) IB ON IL.OWNER_ID = IB.OWNER_ID AND IL.SKU_ID = IB.SKU_ID AND IL.UNIT_PRICE = IB.UNIT_PRICE LEFT JOIN ( SELECT IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE,ABS(SUM(IT.QTY)) AS OUT_QTY FROM @_@INV_TRANS IT LEFT JOIN @_@ORDERS O ON IT.DOC_ID = O.ORDER_ID WHERE IT.TRANS_TYPE = 'OT' AND IT.SOURCE_TRANS_TYPE = 'PICKINGUPDATE' AND IT.STATUS = 'OK' AND O.TYPE <> 'RETURN' AND IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE ) OB ON IL.OWNER_ID = OB.OWNER_ID AND IL.SKU_ID = OB.SKU_ID AND IL.UNIT_PRICE = OB.UNIT_PRICE LEFT JOIN (  SELECT IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE,SUM(IT.QTY) AS AJ_QTY   FROM @_@INV_TRANS IT  WHERE IT.[STATUS] = 'OK' AND IT.TRANS_TYPE IN ('AJ','MV') AND IT.SOURCE_TRANS_TYPE IN ('AdjustmentDetailAdd','CycleCountAdd','TransferDetailAdd','TransferDetailUpdate')  AND IT.TRANS_DATE BETWEEN @BEGIN_DATE AND @END_DATE  GROUP BY IT.OWNER_ID,IT.SKU_ID,IT.UNIT_PRICE  ) AJ ON IL.OWNER_ID = AJ.OWNER_ID AND IL.SKU_ID = AJ.SKU_ID AND IL.UNIT_PRICE = AJ.UNIT_PRICE  LEFT JOIN @_@SKU SKU ON IL.OWNER_ID = SKU.OWNER_ID AND IL.SKU_ID = SKU.SKU_ID  LEFT JOIN @_@SKU_CLASS SC ON SKU.OWNER_ID = SC.OWNER_ID AND SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID  LEFT JOIN @_@PACK P ON SKU.PACK_ID = P.PACK_ID  LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1  LEFT JOIN @_@LOT_ATTRIBUTE LA ON IL.LOT = LA.LOT  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = IL.OWNER_ID AND UO.[USER_ID] = @USER_ID ";
            }
            sql = sql.Replace("@BEGIN_DATE", "'" + financeInOutStockDetailRptQueryEntity.StartTime + "'").Replace("@END_DATE", "'" + financeInOutStockDetailRptQueryEntity.EndTime + "'");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            sql = sql.Replace("@_@", whLoginID).ToString().Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            if (!financeInOutStockDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql.ToString(), financeInOutStockDetailRptQueryEntity.CurrentPage, financeInOutStockDetailRptQueryEntity.PageSize, financeInOutStockDetailRptQueryEntity.SortField, financeInOutStockDetailRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + financeInOutStockDetailRptQueryEntity.SortField + " " + financeInOutStockDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetFinanceSalesDetailByDateRptDataSet(FinanceSalesDetailRptQueryEntiry financeSalesDetailRptQueryEntiry, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSelectSql = new StringBuilder();
            if (financeSalesDetailRptQueryEntiry.BY_CUSTOMER == "Y")
            {
                strSelectSql.Append(" DECLARE @SQL VARCHAR(8000)  IF OBJECT_ID('TEMPDB.DBO.##TABLE') IS NOT NULL BEGIN  DROP TABLE ##TABLE END ");
                strSelectSql.Append(" SET @SQL = 'SELECT  O.OWNER_ID,OD.SKU_ID,SUM(PD.QTY) AS SHIPPED_QTY,S.DESCR AS SKU_DESCR ,S.PACK_ID,U.UOM_DESCR,L.PRODUCE_DATE,L.EXPIRY_DATE,R.PO_ID,(SELECT TOP 1 UNIT_PRICE FROM @_@INV_TRANS WHERE LOT =PD.LOT ) AS UNIT_PRICE,PO.PO_DATE AS ORDER_DATE '  ");
                strSelectSql.Append(" SELECT @SQL = @SQL + ' , SUM(CASE C_COMPANY WHEN ''' + C_COMPANY + ''' THEN PD.QTY ELSE 0 END) [' + C_COMPANY + '] ' ");
                strSelectSql.AppendFormat(" FROM (SELECT DISTINCT C_COMPANY FROM  @_@ORDERS O INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = '{0}' WHERE C_COMPANY IS NOT NULL AND TYPE !='TRANSFER' AND TYPE !='EXCHANGE' AND STATUS IN ('PARTSHIPPED','SHIPPED')) AS A ", pubParasInfo.UserID);
                strSelectSql.AppendFormat(" SET @SQL = @SQL + 'FROM @_@ORDER_DETAIL OD INNER JOIN  @_@ORDERS O  ON O.ORDER_ID =OD.ORDER_ID LEFT JOIN  @_@SKU S ON OD.OWNER_ID=S.OWNER_ID AND OD.SKU_ID =S.SKU_ID   LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID  LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1", new object[0]);
                strSelectSql.Append(" INNER JOIN  @_@PICK_DETAIL  PD ON PD.ORDER_ID =OD.ORDER_ID AND PD.ORDER_LINE_ID = OD.LINE_ID  LEFT JOIN  @_@LOT_ATTRIBUTE L ON PD.LOT=L.LOT  LEFT JOIN  @_@RECEIPT R  ON L.LOT_ATTR10=R.RECEIPT_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@PURCHASE_ORDER PO ON R.PO_ID=PO.PO_ID ");
                strSelectSql.AppendFormat("   INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = ''{0}'' ", pubParasInfo.UserID);
                strSelectSql.AppendFormat(" WHERE   O.TYPE !=''TRANSFER'' AND O.TYPE !=''EXCHANGE'' AND (OD.STATUS=''SHIPPED''OR OD.STATUS =''PartShipped'') AND OD.ACTUAL_SHIP_DATE  BETWEEN ''{0}''  AND ''{1}'' ", financeSalesDetailRptQueryEntiry.StartDatetime, financeSalesDetailRptQueryEntiry.EndDatetime);
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.OwnerID))
                {
                    strSelectSql.AppendFormat(" AND OD.OWNER_ID {0}", financeSalesDetailRptQueryEntiry.OwnerID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.SkuID))
                {
                    strSelectSql.AppendFormat(" AND OD.SKU_ID {0}", financeSalesDetailRptQueryEntiry.SkuID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.CustomerID))
                {
                    strSelectSql.AppendFormat(" AND O.CONSIGNEE_ID {0}", financeSalesDetailRptQueryEntiry.CustomerID.Replace("'", "''"));
                }
                strSelectSql.Append(" GROUP BY O.CONSIGNEE_ID,O.OWNER_ID,OD.SKU_ID,S.DESCR,S.PACK_ID,U.UOM_DESCR,L.PRODUCE_DATE,L.EXPIRY_DATE,R.PO_ID,UNIT_PRICE,PD.LOT,PO.PO_DATE ORDER BY O.CONSIGNEE_ID DESC '");
                strSelectSql.Append(" EXEC(@SQL)   ");
            }
            else
            {
                strSelectSql.Append(" DECLARE @SQL VARCHAR(8000) ");
                strSelectSql.Append(" DECLARE @STARTTIME DATETIME ");
                strSelectSql.Append(" DECLARE @ENDTIME DATETIME ");
                strSelectSql.AppendFormat("  SELECT @STARTTIME=CONVERT(DATETIME,'{0}') ", financeSalesDetailRptQueryEntiry.StartDatetime);
                strSelectSql.AppendFormat("  SELECT @ENDTIME=CONVERT(DATETIME,'{0}') ", financeSalesDetailRptQueryEntiry.EndDatetime);
                strSelectSql.Append("  IF OBJECT_ID('TEMPDB.DBO.##TimeTable') IS NOT NULL  ");
                strSelectSql.Append("  BEGIN  DROP TABLE ##TimeTable  END ");
                strSelectSql.Append("  SELECT  @STARTTIME as TIME INTO ##TimeTable ");
                strSelectSql.Append("  WHILE  @STARTTIME<@ENDTIME ");
                strSelectSql.Append("  BEGIN   SET @STARTTIME=dateadd(day,1,@STARTTIME)  ");
                strSelectSql.Append("  INSERT ##TimeTable (TIME)VALUES(Convert(varchar,@STARTTIME))  END ");
                strSelectSql.Append("  SET @SQL = 'SELECT OWNER_ID,SKU_ID,SKU_DESCR,PACK_ID ,UOM_DESCR,SUM(QTY) AS SHIPPED_QTY, PRODUCE_DATE,EXPIRY_DATE,PO_ID,ORDER_DATE,UNIT_PRICE ' ");
                strSelectSql.Append("  SELECT @SQL = @SQL + ',SUM([' + substring(CONVERT(VARCHAR,TIME,110),0,6) + ']) AS  [' + substring(CONVERT(VARCHAR,TIME,110),0,6) + ']' FROM  ##TimeTable TT ORDER BY TIME ");
                strSelectSql.Append("  SET @SQL =@SQL+' FROM ( SELECT ' ");
                strSelectSql.Append("  SELECT @SQL = @SQL + 'CASE  '''+SUBSTRING(CONVERT(VARCHAR,TT.TIME,110),0,6)+'''  WHEN  SUBSTRING(CONVERT(VARCHAR,TEMP.TIMEDATE,110),0,6) THEN sum(TEMP.QTY) ELSE 0 END [' + substring(CONVERT(VARCHAR,TIME,110),0,6) + '],' FROM  ##TimeTable TT ORDER BY TIME ");
                strSelectSql.Append("  SET @SQL = @SQL+'TEMP.SKU_ID,TEMP.OWNER_ID,TEMP.SKU_DESCR,TEMP.PACK_ID,TEMP.UOM_DESCR, SUM(TEMP.QTY) AS QTY,TEMP.PRODUCE_DATE,TEMP.EXPIRY_DATE,TEMP.PO_ID,TEMP.ORDER_DATE,TEMP.UNIT_PRICE  FROM (  ");
                strSelectSql.Append("  SELECT PD.QTY  AS QTY, SUBSTRING(CONVERT(VARCHAR,OD.ACTUAL_SHIP_DATE,110),0,11)  AS TIMEDATE,OD.SKU_ID,OD.OWNER_ID,S.DESCR AS SKU_DESCR ,S.PACK_ID,U.UOM_DESCR,L.PRODUCE_DATE,L.EXPIRY_DATE,R.PO_ID, PO.PO_DATE AS ORDER_DATE,(SELECT TOP 1 UNIT_PRICE FROM @_@INV_LOT WHERE LOT =PD.LOT ) AS UNIT_PRICE  FROM @_@ORDER_DETAIL OD");
                strSelectSql.Append("  LEFT JOIN  @_@ORDERS O ON OD.ORDER_ID =O.ORDER_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@SKU S ON OD.OWNER_ID=S.OWNER_ID AND OD.SKU_ID =S.SKU_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                strSelectSql.Append("  LEFT JOIN  @_@PICK_DETAIL PD ON OD.ORDER_ID =PD.ORDER_ID AND OD.LINE_ID=PD.ORDER_LINE_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@LOT_ATTRIBUTE L ON PD.LOT=L.LOT");
                strSelectSql.Append("  LEFT JOIN  @_@RECEIPT R  ON L.LOT_ATTR10=R.RECEIPT_ID");
                strSelectSql.Append(" LEFT JOIN   @_@PURCHASE_ORDER PO ON R.PO_ID=PO.PO_ID ");
                strSelectSql.AppendFormat("   INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = ''{0}'' ", pubParasInfo.UserID);
                strSelectSql.AppendFormat("  WHERE   O.TYPE !=''TRANSFER'' AND O.TYPE !=''EXCHANGE'' AND (OD.STATUS=''SHIPPED''OR [OD].[STATUS] =''PartShipped'') AND OD.ACTUAL_SHIP_DATE  BETWEEN ''{0}''  AND ''{1}'' ", financeSalesDetailRptQueryEntiry.StartDatetime, financeSalesDetailRptQueryEntiry.EndDatetime);
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.OwnerID))
                {
                    strSelectSql.AppendFormat(" AND OD.OWNER_ID {0}", financeSalesDetailRptQueryEntiry.OwnerID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.SkuID))
                {
                    strSelectSql.AppendFormat(" AND OD.SKU_ID {0}", financeSalesDetailRptQueryEntiry.SkuID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.CustomerID))
                {
                    strSelectSql.AppendFormat(" AND O.CONSIGNEE_ID {0}", financeSalesDetailRptQueryEntiry.CustomerID.Replace("'", "''"));
                }
                strSelectSql.Append("  UNION ALL   ");
                strSelectSql.Append("  SELECT  RD.RECEIVED_QTY*-1 AS QTY, SUBSTRING(CONVERT(VARCHAR,RD.RECEIVED_DATE,110),0,11)AS TIMEDATE,RD.SKU_ID,RD.OWNER_ID,S.DESCR AS SKU_DESCR,S.PACK_ID,U.UOM_DESCR, RD.PRODUCE_DATE,RD.EXPIRY_DATE, R1.PO_ID,  PO.PO_DATE AS ORDER_DATE ,RD.UNIT_PRICE   FROM  @_@RECEIPT_DETAIL RD ");
                strSelectSql.Append("  LEFT JOIN @_@RECEIPT R  ON RD.RECEIPT_ID=R.RECEIPT_ID ");
                strSelectSql.Append("  LEFT JOIN @_@SKU S ON RD.OWNER_ID=S.OWNER_ID AND RD.SKU_ID =S.SKU_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                strSelectSql.Append(" LEFT JOIN  @_@ORDER_DETAIL OD   ON RD.EXTERN_RECEIPT_ID=OD.ORDER_ID AND RD.EXTERN_LINE_ID=OD.LINE_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@PICK_DETAIL PD ON OD.ORDER_ID =PD.ORDER_ID AND OD.LINE_ID=PD.ORDER_LINE_ID ");
                strSelectSql.Append("  LEFT JOIN  @_@LOT_ATTRIBUTE L ON PD.LOT=L.LOT");
                strSelectSql.Append("  LEFT JOIN  @_@RECEIPT R1  ON L.LOT_ATTR10=R1.RECEIPT_ID");
                strSelectSql.Append(" LEFT JOIN   @_@PURCHASE_ORDER PO ON R1.PO_ID=PO.PO_ID ");
                strSelectSql.AppendFormat("   INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = ''{0}'' ", pubParasInfo.UserID);
                strSelectSql.AppendFormat("  WHERE R.RECEIPT_TYPE =''RETURN'' AND RD.STATUS =''RECEIVEDCOMPLETE''  AND RD.RECEIVED_DATE  BETWEEN ''{0}''  AND ''{1}''  ", financeSalesDetailRptQueryEntiry.StartDatetime, financeSalesDetailRptQueryEntiry.EndDatetime);
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.OwnerID))
                {
                    strSelectSql.AppendFormat(" AND RD.OWNER_ID {0}", financeSalesDetailRptQueryEntiry.OwnerID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.SkuID))
                {
                    strSelectSql.AppendFormat(" AND RD.SKU_ID {0}", financeSalesDetailRptQueryEntiry.SkuID.Replace("'", "''"));
                }
                if (!string.IsNullOrEmpty(financeSalesDetailRptQueryEntiry.CustomerID))
                {
                    strSelectSql.AppendFormat(" AND RD.VENDOR_ID {0}", financeSalesDetailRptQueryEntiry.CustomerID.Replace("'", "''"));
                }
                strSelectSql.Append("  ) TEMP ");
                strSelectSql.Append(" GROUP BY TIMEDATE,SKU_ID,OWNER_ID,SKU_DESCR,TEMP.PACK_ID,TEMP.UOM_DESCR ,TEMP.PRODUCE_DATE,TEMP.EXPIRY_DATE,TEMP.PO_ID,TEMP.ORDER_DATE,TEMP.UNIT_PRICE ");
                strSelectSql.Append(" ) TEMP1 GROUP BY SKU_ID,OWNER_ID,SKU_DESCR,PACK_ID,UOM_DESCR,PRODUCE_DATE,EXPIRY_DATE,PO_ID,ORDER_DATE,UNIT_PRICE '");
                strSelectSql.Append("  IF OBJECT_ID('TEMPDB.DBO.##TimeTable') IS NOT NULL  ");
                strSelectSql.Append("  BEGIN   DROP TABLE ##TimeTable  END");
                strSelectSql.Append("  EXEC(@SQL) ");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, strSelectSql.ToString().Replace("@_@", whLoginID));
        }

        public DataSet GetFinanceSalesDetailRptDataSet(List<string> sqlWhere, FinanceSalesDetailRptQueryEntiry financeSalesDetailRptQueryEntiry, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSelectSql = new StringBuilder();
            if (financeSalesDetailRptQueryEntiry.SHOW_DATE == "N")
            {
                strSelectSql.Append("SELECT  OD.OWNER_ID, OD.SKU_ID, OD.UOM_ID, OD.REMARK,  S.DESCR AS SKU_DESCR, S.DESCR2 AS SKU_DESCR2, UOM.UOM_DESCR,S.PACK_ID,PD.QTY AS SHIPPED_QTY, ");
                strSelectSql.Append(" L.PRODUCE_DATE,L.EXPIRY_DATE,R.PO_ID, PO.PO_DATE AS ORDER_DATE,(SELECT TOP 1 UNIT_PRICE FROM @_@INV_LOT WHERE LOT =PD.LOT) AS UNIT_PRICE");
                strSelectSql.Append(" FROM @_@ORDER_DETAIL OD LEFT JOIN @_@ORDERS [OR] ON (OD.ORDER_ID = [OR].ORDER_ID) ");
                strSelectSql.Append("  LEFT JOIN @_@SKU S ON (OD.OWNER_ID = S.OWNER_ID) AND (OD.SKU_ID = S.SKU_ID) ");
                strSelectSql.Append(" LEFT JOIN  @_@PICK_DETAIL PD ON OD.ORDER_ID =PD.ORDER_ID AND OD.LINE_ID=PD.ORDER_LINE_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@LOT_ATTRIBUTE L ON PD.LOT=L.LOT ");
                strSelectSql.Append(" LEFT JOIN  @_@RECEIPT R  ON L.LOT_ATTR10=R.RECEIPT_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@PURCHASE_ORDER PO ON R.PO_ID=PO.PO_ID ");
                strSelectSql.Append("  LEFT JOIN @_@UOM UOM ON (OD.UOM_ID = UOM.UOM_ID)");
                strSelectSql.AppendFormat("   INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = '{0}' ", pubParasInfo.UserID);
                strSelectSql.Append(" WHERE  ( [OD].[STATUS] = 'Shipped' OR [OD].[STATUS] ='PartShipped'   ) AND [OR].TYPE !='TRANSFER' AND [OR].TYPE !='EXCHANGE'");
            }
            else
            {
                strSelectSql.Append("SELECT  OD.OWNER_ID, OD.SKU_ID, OD.UOM_ID, OD.REMARK,  S.DESCR AS SKU_DESCR, S.DESCR2 AS SKU_DESCR2, UOM.UOM_DESCR,S.PACK_ID,Convert(varchar,[OD].ACTUAL_SHIP_DATE,102) AS ACTUAL_SHIP_DATE,PD.QTY AS SHIPPED_QTY,");
                strSelectSql.Append(" L.PRODUCE_DATE,L.EXPIRY_DATE,R.PO_ID, PO.PO_DATE AS ORDER_DATE,(SELECT TOP 1 UNIT_PRICE FROM @_@INV_LOT WHERE LOT =PD.LOT ) AS UNIT_PRICE");
                strSelectSql.Append(" FROM @_@ORDER_DETAIL OD LEFT JOIN @_@ORDERS [OR] ON (OD.ORDER_ID = [OR].ORDER_ID)");
                strSelectSql.Append("  LEFT JOIN @_@SKU S ON (OD.OWNER_ID = S.OWNER_ID) AND (OD.SKU_ID = S.SKU_ID)");
                strSelectSql.Append(" LEFT JOIN  @_@PICK_DETAIL PD ON OD.ORDER_ID =PD.ORDER_ID AND OD.LINE_ID=PD.ORDER_LINE_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@LOT_ATTRIBUTE L ON PD.LOT=L.LOT ");
                strSelectSql.Append(" LEFT JOIN  @_@RECEIPT R  ON L.LOT_ATTR10=R.RECEIPT_ID ");
                strSelectSql.Append(" LEFT JOIN  @_@PURCHASE_ORDER PO ON R.PO_ID=PO.PO_ID ");
                strSelectSql.Append("  LEFT JOIN @_@UOM UOM ON (OD.UOM_ID = UOM.UOM_ID)");
                strSelectSql.AppendFormat("   INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = '{0}' ", pubParasInfo.UserID);
                strSelectSql.Append(" WHERE  ( [OD].[STATUS] = 'Shipped' OR [OD].[STATUS] ='PartShipped'  ) AND [OR].TYPE !='TRANSFER' AND [OR].TYPE !='EXCHANGE' ");
            }
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSelectSql.Append(" AND " + sqlWhere[i].ToString());
            }
            if (financeSalesDetailRptQueryEntiry.SHOW_DATE == "N")
            {
            }
            string StrSql = strSelectSql.Replace("@_@", whLoginID).ToString();
            if (!financeSalesDetailRptQueryEntiry.IsGetAll)
            {
                StrSql = PagingHelper.GetPagingSQL(strSelectSql.ToString(), financeSalesDetailRptQueryEntiry.CurrentPage, financeSalesDetailRptQueryEntiry.PageSize, financeSalesDetailRptQueryEntiry.SortField, financeSalesDetailRptQueryEntiry.SortDirection);
            }
            else
            {
                StrSql = StrSql + " ORDER BY " + financeSalesDetailRptQueryEntiry.SortField + " " + financeSalesDetailRptQueryEntiry.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, StrSql);
        }

        public DataSet GetGlobalHistoryStockRptDataSet(List<string> sqlWhere, HistoryStockRptQueryEntity historyStockRptQueryEntity, List<string> whLoginID, PubParasInfo pubParasInfo)
        {
            string strWhere = "";
            for (int j = 0; j < sqlWhere.Count; j++)
            {
                strWhere = strWhere + " AND " + sqlWhere[j].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT * FROM ( ");
            for (int i = 0; i < whLoginID.Count; i++)
            {
                if (i > 0)
                {
                    strSql.Append(" UNION ALL ");
                }
                strSql.Append(" SELECT INV.WH_ID, DC.WH_DB_DESC, INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID, P.PACK_UOM1 AS UOM_ID, UOM.UOM_DESCR, ");
                strSql.Append("   SKU.SKU_CLASS_ID, INV.VENDOR_ID, INV.UNIT_PRICE, SKU.SKU_STYLE, PO.CREATED_DATE AS PO_DATE, LAC.DESCR AS SKU_PROPERTY, ");
                strSql.Append("   LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
                strSql.Append("   LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE,  ");
                strSql.Append("   SUM(INV.QTY) AS QTY, SUM(INV.QTY) * SKU.GROSS_WGT AS GROSS_WGT, SUM(INV.QTY) * SKU.[CUBE] AS [CUBE] ");
                strSql.Append(" FROM ( ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptReversal' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'AdjustmentDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PickingUpdate' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ShipmentReversal' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailUpdate' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.WH_ID, it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" ) INV LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = INV.OWNER_ID AND SKU.SKU_ID = INV.SKU_ID ");
                strSql.Append("   LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = SKU.OWNER_ID AND SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID ");
                strSql.Append("   LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID ");
                strSql.Append("   LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1 ");
                strSql.Append("   LEFT JOIN sysadm.DB_CONFIG DC ON DC.DB_LOGIN_ID = INV.WH_ID AND DC.IS_GLOBAL = 'N' ");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = INV.OWNER_ID AND LA.SKU_ID = INV.SKU_ID AND LA.LOT = INV.LOT ");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
                strSql.Append("   LEFT JOIN @_@RECEIPT RECEIPT ON RECEIPT.RECEIPT_ID = LA.LOT_ATTR10 ");
                strSql.Append("   LEFT JOIN @_@PURCHASE_ORDER PO ON PO.PO_ID = RECEIPT.PO_ID ");
                strSql.Append(" WHERE 1 = 1 ");
                strSql.Append(strWhere);
                strSql.Append(" GROUP BY INV.WH_ID, DC.WH_DB_DESC, INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID, P.PACK_UOM1, UOM.UOM_DESCR, ");
                strSql.Append("   SKU.SKU_CLASS_ID, INV.VENDOR_ID, INV.UNIT_PRICE, SKU.SKU_STYLE, SKU.GROSS_WGT, SKU.NET_WGT, SKU.[CUBE], PO.CREATED_DATE, LAC.DESCR,  ");
                strSql.Append("   LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
                strSql.Append("   LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE ");
                strSql.Append(" HAVING SUM(INV.QTY) <> 0 ");
                strSql.Replace("@_@", whLoginID[i]);
            }
            strSql.Append(" ) TEMP");
            string sql = strSql.Replace("@TRANS_DATE", "'" + historyStockRptQueryEntity.INV_DATE + "'").ToString();
            if (!historyStockRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, historyStockRptQueryEntity.CurrentPage, historyStockRptQueryEntity.PageSize, historyStockRptQueryEntity.SortField, historyStockRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + historyStockRptQueryEntity.SortField + " " + historyStockRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetGlobalInventoryRptDataSet(List<string> sqlWhere, GlobalInventoryRptQueryEntity globalInventoryRptQueryEntity, List<string> whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string strSqlWhere = string.Empty;
            for (i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    strSqlWhere = strSqlWhere + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    strSqlWhere = strSqlWhere + " AND " + sqlWhere[i].ToString();
                }
            }
            StringBuilder strSelectSql = new StringBuilder();
            for (i = 0; whLoginID.Count > i; i++)
            {
                strSelectSql.Append(" SELECT DISTINCT A.SKU_ID,B.DESCR,B.DESCR2,A.OWNER_ID,B.SKU_CLASS_ID,F.DESCR AS SKU_CLASS_DESCR,SUM(A.QTY) AS INVENTORY_QTY,D.PACK_UOM1 AS 'UOM',SUM(CASE C.LOT_ATTR09 WHEN 'OK' THEN A.QTY ELSE 0 END) AS 'OK',SUM(CASE C.LOT_ATTR09 WHEN 'HOLD' THEN A.QTY ELSE 0 END) AS 'HOLD',SUM(CASE C.LOT_ATTR09 WHEN 'DAMAGE' THEN A.QTY ELSE 0 END) AS 'DAMAGE', SUM(CASE A.STATUS WHEN 'HOLD' THEN A.QTY ELSE 0 END) AS 'ONHOLD_QTY',  A.ALLOCATED_QTY,SUM(A.QTY - A.ALLOCATED_QTY - A.PICKED_QTY-CASE A.STATUS WHEN 'HOLD' THEN A.QTY ELSE 0 END) AS AVAILABLE,C.VENDOR_ID ,C.EXTERNAL_LOT,SUM(A.QTY *B.[CUBE] ) AS TOTALCUBE,SUM(A.QTY *B.GROSS_WGT) AS TOTALWGT,MAX(C.RECEIPT_DATE) AS RECEIPT_DATE,C.LOT_ATTR01,C.LOT_ATTR02,C.LOT_ATTR03,C.LOT_ATTR04,C.LOT_ATTR05,C.LOT_ATTR06,C.LOT_ATTR07,C.LOT_ATTR08,C.LOT_ATTR09,C.LOT_ATTR10,C.PRODUCE_DATE,C.EXPIRY_DATE, ");
                strSelectSql.AppendFormat(" (SELECT MAX(UPDATED_DATE)  FROM {0}PICK_DETAIL WHERE LOT=A.LOT AND STATUS = 'SHIPPED' ) AS SHIPPED_DATE ", whLoginID[i]);
                strSelectSql.AppendFormat("  FROM {0}INV_LOT_LOC_LPN A ", whLoginID[i]);
                strSelectSql.AppendFormat("  LEFT JOIN {0}SKU B ON A.SKU_ID =B.SKU_ID AND A.OWNER_ID = B.OWNER_ID", whLoginID[i]);
                strSelectSql.AppendFormat("  LEFT JOIN {0}LOT_ATTRIBUTE C ON A.LOT=C.LOT", whLoginID[i]);
                strSelectSql.AppendFormat("  LEFT JOIN {0}PACK D ON B.PACK_ID= D.PACK_ID", whLoginID[i]);
                strSelectSql.AppendFormat("  LEFT JOIN {0}SKU_CLASS F ON B.SKU_CLASS_ID=F.SKU_CLASS_ID AND B.OWNER_ID = F.OWNER_ID", whLoginID[i]);
                strSelectSql.AppendFormat("  INNER JOIN SYSADM.USER_OWNER G ON A.OWNER_ID = G.OWNER_ID AND G.[USER_ID] = '{0}'", pubParasInfo.UserID);
                strSelectSql.AppendFormat("  {0} ", strSqlWhere);
                strSelectSql.AppendFormat("  GROUP BY A.SKU_ID,A.OWNER_ID,B.DESCR,B.DESCR2,B.SKU_CLASS_ID,F.DESCR,C.VENDOR_ID,D.PACK_UOM1,C.EXTERNAL_LOT,A.ALLOCATED_QTY,C.LOT_ATTR01,C.LOT_ATTR02,C.LOT_ATTR03,C.LOT_ATTR04,C.LOT_ATTR05,C.LOT_ATTR06,C.LOT_ATTR07,C.LOT_ATTR08,C.LOT_ATTR09,C.LOT_ATTR10,C.PRODUCE_DATE,C.EXPIRY_DATE,A.LOT", new object[0]);
                if (whLoginID.Count > (i + 1))
                {
                    strSelectSql.AppendFormat(" UNION ALL ", new object[0]);
                }
            }
            strSelectSql.Insert(0, "SELECT SKU_ID,DESCR,DESCR2,OWNER_ID,SKU_CLASS_ID, SKU_CLASS_DESCR,SUM(INVENTORY_QTY) AS INVENTORY_QTY ,UOM,SUM(OK) AS OK,SUM(HOLD) AS HOLD,SUM(DAMAGE) AS DAMAGE,SUM(ONHOLD_QTY) AS ONHOLD_QTY,SUM(ALLOCATED_QTY) AS ALLOCATED_QTY,SUM(AVAILABLE) AS AVAILABLE,SUM(TOTALCUBE) AS TOTALCUBE,SUM(TOTALWGT) AS TOTALWGT,max(RECEIPT_DATE) AS RECEIPT_DATE,Max(SHIPPED_DATE) AS SHIPPED_DATE,VENDOR_ID,EXTERNAL_LOT,LOT_ATTR01,LOT_ATTR02,LOT_ATTR03,LOT_ATTR04,LOT_ATTR05,LOT_ATTR06,LOT_ATTR07,LOT_ATTR08,LOT_ATTR09,LOT_ATTR10,PRODUCE_DATE,EXPIRY_DATE  FROM(  ");
            strSelectSql.Append(" ) INV WHERE  INVENTORY_QTY>0 GROUP BY SKU_ID,OWNER_ID,DESCR,DESCR2,SKU_CLASS_ID,SKU_CLASS_DESCR,VENDOR_ID,UOM,EXTERNAL_LOT,ALLOCATED_QTY,VENDOR_ID,EXTERNAL_LOT,LOT_ATTR01,LOT_ATTR02,LOT_ATTR03,LOT_ATTR04,LOT_ATTR05,LOT_ATTR06,LOT_ATTR07,LOT_ATTR08,LOT_ATTR09,LOT_ATTR10,PRODUCE_DATE,EXPIRY_DATE");
            string StrSql = strSelectSql.ToString();
            if (!globalInventoryRptQueryEntity.IsGetAll)
            {
                StrSql = PagingHelper.GetPagingSQL(strSelectSql.ToString(), globalInventoryRptQueryEntity.CurrentPage, globalInventoryRptQueryEntity.PageSize, globalInventoryRptQueryEntity.SortField, globalInventoryRptQueryEntity.SortDirection);
            }
            else
            {
                StrSql = StrSql + " ORDER BY " + globalInventoryRptQueryEntity.SortField + " " + globalInventoryRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, StrSql);
        }

        public DataSet GetHistoryStockRptDataSet(List<string> sqlWhere, HistoryStockRptQueryEntity historyStockRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string sql = string.Empty;
            StringBuilder strSql = new StringBuilder();
            InvBackUpDA invBackUpDA = new InvBackUpDA();
            if (invBackUpDA.GetInvBackUpByID(historyStockRptQueryEntity.INV_DATE, whLoginID) == null)
            {
                strSql.Append(" SELECT DISTINCT OWNER_ID, SKU_ID, DESCR, LOC, LOT, LPN_ID, PACK_ID, UOM_ID, UOM_DESCR, SKU_CLASS_ID, VENDOR_ID, UNIT_PRICE, SKU_STYLE, PO_DATE, SKU_PROPERTY, ");
                strSql.Append(" LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10, ");
                strSql.Append(" PRODUCE_DATE, [EXPIRY_DATE], EXTERNAL_LOT, RECEIPT_DATE, SUM(QTY) AS QTY, SUM(QTY) * SKU_GROSS_WGT AS GROSS_WGT, SUM(QTY) * SKU_CUBE AS [CUBE] ");
                strSql.Append(" FROM ( ");
                strSql.Append(" SELECT DISTINCT INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID,SKU.GROSS_WGT AS SKU_GROSS_WGT,SKU.CUBE AS SKU_CUBE, ");
                strSql.Append(" P.PACK_UOM1 AS UOM_ID, UOM.UOM_DESCR, SKU.SKU_CLASS_ID, LA.VENDOR_ID, INV.UNIT_PRICE, SKU.SKU_STYLE, PO.CREATED_DATE AS PO_DATE, LAC.DESCR AS SKU_PROPERTY, ");
                strSql.Append(" LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
                strSql.Append(" LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE, INV.QTY ");
                strSql.Append(" FROM ( ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptReversal' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'AdjustmentDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PickingUpdate' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ShipmentReversal' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailUpdate' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" UNION ALL ");
                strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
                strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
                strSql.Append(" FROM @_@INV_TRANS it ");
                strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
                strSql.Append(" ) INV LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = INV.OWNER_ID AND SKU.SKU_ID = INV.SKU_ID ");
                strSql.Append("   LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = SKU.OWNER_ID AND SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID ");
                strSql.Append("   LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID");
                strSql.Append("   LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = INV.OWNER_ID AND LA.SKU_ID = INV.SKU_ID AND LA.LOT = INV.LOT ");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
                strSql.Append("   LEFT JOIN @_@RECEIPT RECEIPT ON RECEIPT.RECEIPT_ID = LA.LOT_ATTR10 ");
                strSql.Append("   LEFT JOIN @_@PURCHASE_ORDER PO ON PO.PO_ID = RECEIPT.PO_ID ");
                strSql.Append(" WHERE 1=1 ");
                for (i = 0; i < sqlWhere.Count; i++)
                {
                    strSql.Append(" AND " + sqlWhere[i].ToString());
                }
                strSql.Append(" ) TEMP ");
                strSql.Append(" GROUP BY OWNER_ID, SKU_ID, DESCR, LOC, LOT, LPN_ID, PACK_ID, UOM_ID, UOM_DESCR, ");
                strSql.Append(" SKU_CLASS_ID, VENDOR_ID, UNIT_PRICE, SKU_STYLE, PO_DATE, SKU_PROPERTY, SKU_GROSS_WGT,SKU_CUBE, ");
                strSql.Append(" LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10, ");
                strSql.Append(" PRODUCE_DATE, [EXPIRY_DATE], EXTERNAL_LOT, RECEIPT_DATE ");
                strSql.Append(" HAVING SUM(QTY) <> 0 ");
                sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@TRANS_DATE", "'" + historyStockRptQueryEntity.INV_DATE + "'");
            }
            else
            {
                strSql.Append(" SELECT INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID, P.PACK_UOM1 AS UOM_ID, UOM.UOM_DESCR, ");
                strSql.Append("   SKU.SKU_CLASS_ID, LA.VENDOR_ID, INV_LOT.UNIT_PRICE, SKU.SKU_STYLE, PO.CREATED_DATE AS PO_DATE, LAC.DESCR AS SKU_PROPERTY, ");
                strSql.Append("   LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
                strSql.Append("   LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE,  ");
                strSql.Append("   INV.QTY AS QTY, INV.QTY * SKU.GROSS_WGT AS GROSS_WGT, INV.QTY * SKU.[CUBE] AS [CUBE] ");
                strSql.Append(" FROM @_@INV_BACK_UP INV ");
                strSql.Append("   LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = INV.OWNER_ID AND SKU.SKU_ID = INV.SKU_ID ");
                strSql.Append("   LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = SKU.OWNER_ID AND SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID ");
                strSql.Append("   LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID");
                strSql.Append("   LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = INV.OWNER_ID AND LA.SKU_ID = INV.SKU_ID AND LA.LOT = INV.LOT ");
                strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
                strSql.Append("   LEFT JOIN @_@INV_LOT ON INV_LOT.LOT = INV.LOT ");
                strSql.Append("   LEFT JOIN @_@RECEIPT RECEIPT ON RECEIPT.RECEIPT_ID = LA.LOT_ATTR10 ");
                strSql.Append("   LEFT JOIN @_@PURCHASE_ORDER PO ON PO.PO_ID = RECEIPT.PO_ID ");
                strSql.Append(" WHERE CONVERT(VARCHAR(20),EXECUTE_DATE,23) = @EXECUTE_DATE ");
                for (i = 0; i < sqlWhere.Count; i++)
                {
                    strSql.Append(" AND " + sqlWhere[i].ToString());
                }
                sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@EXECUTE_DATE", "'" + Convert.ToDateTime(historyStockRptQueryEntity.INV_DATE).ToString("yyyy-MM-dd") + "'");
            }
            if (!historyStockRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, historyStockRptQueryEntity.CurrentPage, historyStockRptQueryEntity.PageSize, historyStockRptQueryEntity.SortField, historyStockRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + historyStockRptQueryEntity.SortField + " " + historyStockRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetIdleInventoryRptDataSet(List<string> sqlWhere, IdleInventoryRptQueryEntiry idleInventoryRptQueryEntiry, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(" SELECT * FROM ( ");
            sbSql.Append(" SELECT ILLL.OWNER_ID, ILLL.SKU_ID, ILLL.LOC, LA.RECEIPT_DATE, LA.LOT_ATTR08,SKU.SKU_CLASS_ID,SKU.SKU_GROUP,SKU.SKU_GROUP2,SUM(ILLL.QTY) AS QTY, DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) AS DAYS ");
            sbSql.Append(" FROM @_@INV_LOT_LOC_LPN ILLL LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = ILLL.OWNER_ID AND LA.SKU_ID = ILLL.SKU_ID AND LA.LOT = ILLL.LOT ");
            sbSql.Append(" LEFT JOIN @_@SKU SKU ON SKU.SKU_ID = ILLL.SKU_ID AND SKU.OWNER_ID = ILLL.OWNER_ID ");
            sbSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON ILLL.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            sbSql.Append(" WHERE ILLL.QTY > 0 ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sbSql.Append(" AND " + sqlWhere[i].ToString());
            }
            if (idleInventoryRptQueryEntiry.MIN_DAYS > 0)
            {
                sbSql.Append(" AND DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) >= " + idleInventoryRptQueryEntiry.MIN_DAYS.ToString());
            }
            if (idleInventoryRptQueryEntiry.MAX_DAYS > 0)
            {
                sbSql.Append(" AND DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) <= " + idleInventoryRptQueryEntiry.MAX_DAYS.ToString());
            }
            sbSql.Append(" GROUP BY ILLL.OWNER_ID, ILLL.SKU_ID, ILLL.LOC, LA.RECEIPT_DATE, LA.LOT_ATTR08,SKU.SKU_CLASS_ID,SKU.SKU_GROUP,SKU.SKU_GROUP2 ) tmp");
            string sql = sbSql.ToString().Replace("@_@", whLoginID);
            if (!idleInventoryRptQueryEntiry.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, idleInventoryRptQueryEntiry.CurrentPage, idleInventoryRptQueryEntiry.PageSize, idleInventoryRptQueryEntiry.SortField, idleInventoryRptQueryEntiry.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + idleInventoryRptQueryEntiry.SortField + " " + idleInventoryRptQueryEntiry.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetImportDeclarationsRptDateSet(List<string> sqlWhere, ImportDeclarationsRptQueryEntity importDeclarationsRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT IDS.DECLARATIONS_DATE,IDS.DECLARATIONS_ID,IDS.COMPANY_DECLARATIONGS_ID,IDS.VERIFICATION_FORM_ID,IDS.OWNER_ID,IDS.OWNER_ORDER_ID,IDD.SKU_ID,INO.ITEM_NO_UOM,SUM(IDD.QTY) AS QTY,IDD.UNIT_PRICE,S.DESCR AS SKU_DESCR,IDD.ITEM_NO_ID,INO.DESCR AS ITEM_NO_DESCR,SUM(IDD.[CUBE]) AS [CUBE],SUM(IDD.GROSS_WGT) AS GROSS_WGT,SUM(IDD.NET_WGT) AS NET_WGT,SUM(IDD.EXTENDED_PRICE) AS EXTENDED_PRICE,SUM(CONVERT(FLOAT,ISNULL(IDD.UDF1,'0'))) AS UDF1,SUM(CONVERT(FLOAT,ISNULL(IDD.UDF2,'0'))) AS UDF2  ");
            strSql.Append(" FROM @_@IMPORT_DECLARATIONS IDS LEFT JOIN @_@IMPORT_DECLARATIONS_DETAIL IDD ON IDS.DECLARATIONS_ID=IDD.DECLARATIONS_ID ");
            strSql.Append(" LEFT JOIN @_@SKU S ON IDD.OWNER_ID=S.OWNER_ID AND IDD.SKU_ID = S.SKU_ID ");
            strSql.Append(" LEFT JOIN @_@ITEM_NO INO ON IDD.ITEM_NO_ID=INO.ITEM_NO_ID ");
            strSql = strSql.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    strSql.AppendFormat(" WHERE  {0}", sqlWhere[i].ToString());
                }
                else
                {
                    strSql.AppendFormat(" AND {0}", sqlWhere[i].ToString());
                }
            }
            strSql.Append("GROUP BY IDS.DECLARATIONS_DATE,IDS.DECLARATIONS_ID,IDS.COMPANY_DECLARATIONGS_ID,IDS.VERIFICATION_FORM_ID,IDS.OWNER_ID,IDS.OWNER_ORDER_ID,IDD.SKU_ID,INO.ITEM_NO_UOM,IDD.UNIT_PRICE,S.DESCR ,IDD.ITEM_NO_ID,INO.DESCR ");
            if (!importDeclarationsRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), importDeclarationsRptQueryEntity.CurrentPage, importDeclarationsRptQueryEntity.PageSize, importDeclarationsRptQueryEntity.SortField, importDeclarationsRptQueryEntity.SortDirection);
            }
            else
            {
                sql = strSql.ToString() + " ORDER BY " + importDeclarationsRptQueryEntity.SortField + " " + importDeclarationsRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInOutBlanaceRptDataSet(List<string> sqlWhere, InOutBlanaceRptQueryEntity inOutBlanaceRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strOwner;
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            if (inOutBlanaceRptQueryEntity.ShowLot == "Y")
            {
                strOwner = string.Empty;
                if (!string.IsNullOrEmpty(inOutBlanaceRptQueryEntity.OwnerID))
                {
                    strOwner = " and IT.OWNER_ID" + inOutBlanaceRptQueryEntity.OwnerID;
                }
                sql = " SELECT il.OWNER_ID, il.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR, la.VENDOR_ID,s.udf2,s.SKU_GROUP,SC.DESCR AS SKU_CLASS_DESCR,   ISNULL(A.UNIT_PRICE,0) AS UNIT_PRICE,ISNULL(A.UNIT_PRICE,0) AS INIT_PRICE,ISNULL(A.UNIT_PRICE,0)*ISNULL( SUM(iL.BEGINQTY),0) AS INIT_AMOUNT,  ISNULL(SUM(iL.INQTY),0)*ISNULL(A.UNIT_PRICE,0) AS IN_AMOUNT,ISNULL(SUM(iL.OTQTY),0)*ISNULL(A.UNIT_PRICE,0) AS OUT_AMOUNT,  ISNULL(SUM(iL.IN_R_QTY),0)*ISNULL(A.UNIT_PRICE,0) AS IN_R_AMOUNT, ISNULL(SUM(iL.OT_R_QTY),0)*ISNULL(A.UNIT_PRICE,0) AS OUT_R_AMOUNT,  SUM(iL.BEGINQTY) AS INIT_QTY, SUM(iL.INQTY) AS IN_QTY, SUM(iL.IN_R_QTY) AS IN_R_QTY, SUM(iL.OTQTY) AS OUT_QTY, SUM(iL.OT_R_QTY) AS OUT_R_QTY, SUM(iL.AJQTY) AS AJ_QTY,   ISNULL(SUM(iL.AJQTY),0)*ISNULL(A.UNIT_PRICE,0) AS AJ_AMOUNT,ISNULL(A.UNIT_PRICE,0) AS END_PRICE,  ISNULL(A.UNIT_PRICE,0)* ISNULL(SUM(iL.ENDQTY),0) AS END_AMOUNT,  ISNULL(SUM(iL.ENDQTY),0) AS END_QTY,  ISNULL(SUM(iL.ENDQTY),0) * s.[CUBE] AS TOTALCUBE,   ISNULL(SUM(iL.ENDQTY),0) * s.GROSS_WGT AS TOTALWGT,  SUM(A.QTY-A.PREALLOCATED_QTY-ALLOCATED_QTY-PICKED_QTY-ONHOLD_QTY) AS END_AVAILABLE_QTY,  LA.EXTERNAL_LOT AS EXTERNAL_LOT  ,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.RECEIPT_DATE AS RECEIPT_DATE, LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03,  LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05, LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08, LA.LOT_ATTR09 AS LOT_ATTR09,  LA.LOT_ATTR10 AS LOT_ATTR10,s.PACK_ID,u.UOM_DESCR   FROM (  SELECT IT.LOT, IT.OWNER_ID, IT.SKU_ID,  SUM(CASE WHEN IT.TRANS_DATE < @BEGIN_DATE AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS BEGINQTY,  SUM(CASE WHEN IT.TRANS_DATE <= @END_DATE AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')   THEN IT.QTY ELSE 0 END) AS ENDQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' AND ISNULL(R.RECEIPT_TYPE,'') <> 'RETURN' THEN IT.QTY ELSE 0 END) AS INQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' AND ISNULL(R.RECEIPT_TYPE,'') = 'RETURN' THEN IT.QTY ELSE 0 END) AS IN_R_QTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE IN ('AJADJUSTMENTDETAILADD','AJCYCLECOUNTADD','MVTRANSFERDETAILADD','MVTRANSFERDETAILUPDATE')  THEN IT.QTY ELSE 0 END) AS AJQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' AND ISNULL(O.TYPE,'') <> 'RETURN'  THEN IT.QTY ELSE 0 END) AS OTQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' AND ISNULL(O.TYPE,'') = 'RETURN'  THEN IT.QTY ELSE 0 END) AS OT_R_QTY  FROM @_@INV_TRANS IT  LEFT JOIN @_@RECEIPT R ON IT.DOC_ID = R.RECEIPT_ID AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK'   LEFT JOIN @_@PICK_DETAIL PD ON PD.PICK_DETAIL_ID=IT.DOC_ID AND IT.TRANS_TYPE = 'OT' LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID where  1=1 " + strOwner + " GROUP BY IT.LOT, IT.OWNER_ID, IT.SKU_ID) IL  LEFT JOIN @_@INV_LOT A ON A.LOT = iL.LOT AND A.OWNER_ID = iL.OWNER_ID AND A.SKU_ID = iL.SKU_ID  LEFT JOIN @_@SKU s ON s.OWNER_ID = iL.OWNER_ID AND s.SKU_ID = iL.SKU_ID  LEFT JOIN @_@PACK p ON p.PACK_ID = s.PACK_ID  LEFT JOIN @_@UOM u ON u.UOM_ID = p.PACK_UOM1  LEFT JOIN @_@LOT_ATTRIBUTE la ON la.LOT = iL.LOT AND la.OWNER_ID = iL.OWNER_ID AND la.SKU_ID = iL.SKU_ID  LEFT JOIN @_@SKU_CLASS SC ON s.OWNER_ID = SC.OWNER_ID AND s.SKU_CLASS_ID = SC.SKU_CLASS_ID  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = iL.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE ( ISNULL(iL.BEGINQTY,0) <> 0 OR ISNULL(iL.INQTY,0) <> 0 OR ISNULL(iL.IN_R_QTY,0) <> 0 OR ISNULL(iL.OTQTY,0) <> 0 OR ISNULL(iL.ENDQTY,0) <> 0  OR  ISNULL(iL.OT_R_QTY,0) <> 0  OR  ISNULL(iL.AJQTY,0) <> 0  ) " + strWhere + " GROUP BY il.OWNER_ID, il.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR, la.VENDOR_ID,s.udf2,s.SKU_GROUP,SC.DESCR ,A.unit_price,  LA.EXTERNAL_LOT ,LA.PRODUCE_DATE ,LA.EXPIRY_DATE ,LA.RECEIPT_DATE , LA.LOT_ATTR01 ,LA.LOT_ATTR02 ,LA.LOT_ATTR03 ,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06 ,LA.LOT_ATTR07 ,LA.LOT_ATTR08 , LA.LOT_ATTR09 ,LA.LOT_ATTR10,s.PACK_ID,u.UOM_DESCR  ";
            }
            else
            {
                strOwner = string.Empty;
                if (!string.IsNullOrEmpty(inOutBlanaceRptQueryEntity.OwnerID))
                {
                    strOwner = " and IT.OWNER_ID" + inOutBlanaceRptQueryEntity.OwnerID;
                }
                sql = " SELECT il.OWNER_ID, il.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR, s.udf2,s.SKU_GROUP,SC.DESCR AS SKU_CLASS_DESCR,   ISNULL(A.UNIT_PRICE,0) AS UNIT_PRICE,ISNULL(A.UNIT_PRICE,0) AS INIT_PRICE,ISNULL(A.UNIT_PRICE,0)*ISNULL( SUM(iL.BEGINQTY),0) AS INIT_AMOUNT,  ISNULL(SUM(iL.INQTY),0)*ISNULL(A.UNIT_PRICE,0) AS IN_AMOUNT,ISNULL(SUM(iL.OTQTY),0)*ISNULL(A.UNIT_PRICE,0) AS OUT_AMOUNT,  ISNULL(SUM(iL.IN_R_QTY),0)*ISNULL(A.UNIT_PRICE,0) AS IN_R_AMOUNT, ISNULL(SUM(iL.OT_R_QTY),0)*ISNULL(A.UNIT_PRICE,0) AS OUT_R_AMOUNT,  SUM(iL.BEGINQTY) AS INIT_QTY, SUM(iL.INQTY) AS IN_QTY, SUM(iL.IN_R_QTY) AS IN_R_QTY, SUM(iL.OTQTY) AS OUT_QTY, SUM(iL.OT_R_QTY) AS OUT_R_QTY, SUM(iL.AJQTY) AS AJ_QTY,   ISNULL(SUM(iL.AJQTY),0)*ISNULL(A.UNIT_PRICE,0) AS AJ_AMOUNT,ISNULL(A.UNIT_PRICE,0) AS END_PRICE,  ISNULL(A.UNIT_PRICE,0)* ISNULL(SUM(iL.ENDQTY),0) AS END_AMOUNT,  ISNULL(SUM(iL.ENDQTY),0) AS END_QTY,  ISNULL(SUM(iL.ENDQTY),0) * s.[CUBE] AS TOTALCUBE,   ISNULL(SUM(iL.ENDQTY),0) * s.GROSS_WGT AS TOTALWGT,  SUM(A.QTY-A.PREALLOCATED_QTY-ALLOCATED_QTY-PICKED_QTY-ONHOLD_QTY) AS END_AVAILABLE_QTY ,s.PACK_ID,u.UOM_DESCR FROM (  SELECT IT.LOT, IT.OWNER_ID, IT.SKU_ID,  SUM(CASE WHEN IT.TRANS_DATE < @BEGIN_DATE AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS BEGINQTY,  SUM(CASE WHEN IT.TRANS_DATE <= @END_DATE AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')   THEN IT.QTY ELSE 0 END) AS ENDQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' AND ISNULL(R.RECEIPT_TYPE,'') <> 'RETURN' THEN IT.QTY ELSE 0 END) AS INQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' AND ISNULL(R.RECEIPT_TYPE,'') = 'RETURN' THEN IT.QTY ELSE 0 END) AS IN_R_QTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE  IN ('AJADJUSTMENTDETAILADD','AJCYCLECOUNTADD','MVTRANSFERDETAILADD','MVTRANSFERDETAILUPDATE')  THEN IT.QTY ELSE 0 END) AS AJQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' AND ISNULL(O.TYPE,'') <> 'RETURN'  THEN IT.QTY ELSE 0 END) AS OTQTY,  SUM(CASE WHEN IT.TRANS_DATE >= @BEGIN_DATE AND IT.TRANS_DATE <= @END_DATE  AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' AND ISNULL(O.TYPE,'') = 'RETURN'  THEN IT.QTY ELSE 0 END) AS OT_R_QTY  FROM @_@INV_TRANS IT  LEFT JOIN @_@RECEIPT R ON IT.DOC_ID = R.RECEIPT_ID AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK'  LEFT JOIN @_@PICK_DETAIL PD ON PD.PICK_DETAIL_ID=IT.DOC_ID AND IT.TRANS_TYPE = 'OT' LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID where  1=1 " + strOwner + " GROUP BY IT.LOT, IT.OWNER_ID, IT.SKU_ID) IL  LEFT JOIN @_@INV_LOT A ON A.LOT = iL.LOT AND A.OWNER_ID = iL.OWNER_ID AND A.SKU_ID = iL.SKU_ID  LEFT JOIN @_@SKU s ON s.OWNER_ID = iL.OWNER_ID AND s.SKU_ID = iL.SKU_ID  LEFT JOIN @_@PACK p ON p.PACK_ID = s.PACK_ID  LEFT JOIN @_@UOM u ON u.UOM_ID = p.PACK_UOM1  LEFT JOIN @_@LOT_ATTRIBUTE la ON la.LOT = iL.LOT AND la.OWNER_ID = iL.OWNER_ID AND la.SKU_ID = iL.SKU_ID  LEFT JOIN @_@SKU_CLASS SC ON s.OWNER_ID = SC.OWNER_ID AND s.SKU_CLASS_ID = SC.SKU_CLASS_ID  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = iL.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE (  ISNULL(iL.BEGINQTY,0) <> 0 OR ISNULL(iL.INQTY,0) <> 0 OR ISNULL(iL.IN_R_QTY,0) <> 0 OR ISNULL(iL.OTQTY,0) <> 0 OR ISNULL(iL.ENDQTY,0) <> 0  OR  ISNULL(iL.OT_R_QTY,0) <> 0  OR  ISNULL(iL.AJQTY,0) <> 0 ) " + strWhere + " GROUP BY il.OWNER_ID, il.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR, s.udf2,s.SKU_GROUP,SC.DESCR ,A.unit_price,s.PACK_ID,u.UOM_DESCR ";
            }
            sql = sql.Replace("@BEGIN_DATE", "'" + inOutBlanaceRptQueryEntity.StartTime + "'").Replace("@END_DATE", "'" + inOutBlanaceRptQueryEntity.EndTime + "'").Replace("@_@", whLoginID).ToString();
            if (!inOutBlanaceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, inOutBlanaceRptQueryEntity.CurrentPage, inOutBlanaceRptQueryEntity.PageSize, inOutBlanaceRptQueryEntity.SortField, inOutBlanaceRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + inOutBlanaceRptQueryEntity.SortField + " " + inOutBlanaceRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInOutInv2RptDetailDataSet(List<string> sqlWhere, InOutStockRptDetailQueryEntity inOutStockRptDetailQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT A.OWNER_ID,A.VENDOR_ID,A.SKU_ID,A.DESCR,A.CUSTOM_SKU_NO,A.ITEM_NO_ID,A.ITEM_NO_UOM,A.RECEIPT_ID,A.EXTERNAL_RECEIPT_ID,A.CONSIGNEE_ID,A.RECEIPT_DATE,A.OT_DATE,ORDER_ID,A.EXTERN_ORDER_ID,B.INQTY,A.OTQTY ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT OWNER_ID,VENDOR_ID,SKU_ID,DESCR,CUSTOM_SKU_NO,ITEM_NO_ID,ITEM_NO_UOM,RECEIPT_ID,EXTERNAL_RECEIPT_ID,CONSIGNEE_ID,RECEIPT_DATE,OT_DATE,ORDER_ID,EXTERN_ORDER_ID,SUM(OTQTY) AS OTQTY,TRANS_TYPE ");
            strSql.Append(" FROM( ");
            strSql.Append(" SELECT  ISNULL(IT.OWNER_ID,'') AS OWNER_ID, ISNULL(LA.VENDOR_ID,'') AS VENDOR_ID, IT.SKU_ID,SKU.DESCR,SKU.CUSTOM_SKU_NO,R.RECEIPT_ID,R.EXTERNAL_RECEIPT_ID,ISNULL(LA.LOT_ATTR03,'') AS ITEM_NO_ID,INO.ITEM_NO_UOM, ");
            strSql.Append(" CONVERT(VARCHAR(20),R.RECEIPT_DATE,23) AS RECEIPT_DATE,");
            strSql.Append(" CASE IT.TRANS_TYPE WHEN 'IN' THEN NULL ELSE O.CONSIGNEE_ID END AS CONSIGNEE_ID, ");
            strSql.Append(" CASE IT.TRANS_TYPE WHEN 'IN' THEN NULL ELSE O.ORDER_ID END AS ORDER_ID, ");
            strSql.Append(" CASE IT.TRANS_TYPE WHEN 'IN' THEN NULL ELSE O.EXTERN_ORDER_ID END AS EXTERN_ORDER_ID, ");
            strSql.Append(" CASE IT.TRANS_TYPE WHEN 'IN' THEN NULL ELSE CONVERT(VARCHAR(20),O.ORDER_DATE,23) END AS OT_DATE, ");
            strSql.Append(" 0 AS INQTY,CASE IT.TRANS_TYPE WHEN 'IN' THEN 0 ELSE ISNULL(PD.QTY,0) END AS OTQTY,IT.TRANS_TYPE ");
            strSql.Append(" FROM @_@INV_TRANS IT ");
            strSql.Append(" LEFT JOIN @_@SKU ON SKU.SKU_ID = IT.SKU_ID AND SKU.OWNER_ID = IT.OWNER_ID ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT ");
            strSql.Append(" LEFT JOIN @_@ITEM_NO INO ON INO.ITEM_NO_ID = LA.LOT_ATTR03 ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = LA.LOT_ATTR10 ");
            if (!string.IsNullOrEmpty(inOutStockRptDetailQueryEntity.IMPORT_DECLARATIONS_ID))
            {
                strSql.Append(" LEFT JOIN @_@IMPORT_DECLARATIONS ID ON ID.RECEIPT_ID = R.RECEIPT_ID ");
            }
            strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON PD.LOT = LA.LOT AND PD.STATUS = 'SHIPPED'  AND PD.QTY > 0 ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA2 ON LA2.LOT = PD.LOT ");
            strSql.Append(" LEFT JOIN @_@ORDERS O ON O.ORDER_ID = PD.ORDER_ID ");
            if (!string.IsNullOrEmpty(inOutStockRptDetailQueryEntity.EXPORT_DECLARATIONS_ID))
            {
                strSql.Append(" LEFT JOIN @_@EXPORT_DECLARATIONS ED ON ED.ORDER_ID = O.ORDER_ID ");
            }
            strSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = IT.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append(" WHERE ((IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' ");
            strSql.Append(" OR (LA.LOT IN (SELECT DISTINCT LOT FROM @_@LOT_ATTRIBUTE LA2 WHERE LA2.LOT_ATTR10 = LA.LOT_ATTR10)) AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'OTPickingUpdateOK')) ");
            strSql.AppendFormat(" {0}  ", strWhere);
            strSql.Append(" GROUP BY ISNULL(IT.OWNER_ID,''),ISNULL(LA.VENDOR_ID,''),IT.SKU_ID,SKU.DESCR,SKU.CUSTOM_SKU_NO,R.RECEIPT_ID,R.EXTERNAL_RECEIPT_ID,ISNULL(LA.LOT_ATTR03,''),INO.ITEM_NO_UOM,O.ORDER_ID,O.EXTERN_ORDER_ID,PD.QTY,O.ORDER_DATE,R.RECEIPT_DATE,O.CONSIGNEE_ID,PD.UPDATED_DATE,IT.TRANS_TYPE ");
            strSql.Append(" ) TMP  WHERE (TMP.TRANS_TYPE = 'OT' OR (TMP.TRANS_TYPE = 'IN' AND TMP.ORDER_ID IS NULL))  ");
            strSql.Append(" GROUP BY OWNER_ID,VENDOR_ID,SKU_ID,DESCR,CUSTOM_SKU_NO,ITEM_NO_ID,ITEM_NO_UOM,RECEIPT_ID,EXTERNAL_RECEIPT_ID,CONSIGNEE_ID,RECEIPT_DATE,OT_DATE,ORDER_ID,EXTERN_ORDER_ID,TRANS_TYPE ");
            strSql.Append(" ) A LEFT JOIN ");
            strSql.Append(" (SELECT LA.SKU_ID,ISNULL(LA.OWNER_ID,'') AS OWNER_ID,ISNULL(LA.VENDOR_ID,'') AS VENDOR_ID,LA.LOT_ATTR10,ISNULL(LA.LOT_ATTR03,'') AS LOT_ATTR03,ISNULL(SUM(IT.QTY),0) AS INQTY FROM @_@INV_TRANS IT ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT ");
            strSql.Append(" WHERE  IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' GROUP BY  LA.SKU_ID,ISNULL(LA.OWNER_ID,''),ISNULL(LA.VENDOR_ID,''),LA.LOT_ATTR10,ISNULL(LA.LOT_ATTR03,'') ");
            strSql.Append(" ) B ON B.SKU_ID = A.SKU_ID AND ISNULL(B.OWNER_ID,'') = A.OWNER_ID AND ISNULL(B.VENDOR_ID,'') = A.VENDOR_ID AND B.LOT_ATTR10 = A.RECEIPT_ID AND ISNULL(B.LOT_ATTR03,'') = ISNULL(A.ITEM_NO_ID,'') ");
            strSql.Append(" ORDER BY RECEIPT_ID,OWNER_ID,VENDOR_ID,SKU_ID,ITEM_NO_ID,ORDER_ID ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!inOutStockRptDetailQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), inOutStockRptDetailQueryEntity.CurrentPage, inOutStockRptDetailQueryEntity.PageSize, inOutStockRptDetailQueryEntity.SortField, inOutStockRptDetailQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInOutInvRptDetailDataSet(List<string> sqlWhere, InOutStockRptDetailQueryEntity inOutStockRptDetailQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string strSql = " SELECT B.OWNER_ID,B.VENDOR_ID,B.SKU_ID,B.DESCR,B.LOT_ATTR10,B.RECEIPT_DATE,B.EXTERNAL_LOT,B.OT_EXTERNAL_LOT,B.ORDER_ID,B.CONSIGNEE_ID,B.OT_DATE, B.BEGINQTY,ISNULL(B.AJQTY,0) AS AJQTY,ISNULL(B.INQTY,0) AS INQTY,B.OTQTY , CASE ISNULL(B.ORDER_ID,'') WHEN '' THEN (B.BEGINQTY + B.INQTY) ELSE B.ENDQTY END AS ENDQTY  FROM (  SELECT  ( SELECT SUM(ISNULL([BEGIN].BEGINQTY,0)) AS BEGINQTY FROM  ( SELECT SUM(CASE WHEN IT.TRANS_DATE < @begin AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS BEGINQTY  FROM @_@INV_TRANS IT LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT  WHERE IT.OWNER_ID = A.OWNER_ID AND ISNULL(LA.VENDOR_ID,'') = A.VENDOR_ID AND IT.SKU_ID = A.SKU_ID  ) [BEGIN]) BEGINQTY, ( SELECT SUM(ISNULL([ADJ].AJQTY,0)) AS AJQTY FROM  ( SELECT SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end   AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE IN ('AJADJUSTMENTDETAILADD','AJCYCLECOUNTADD','MVTRANSFERDETAILADD','MVTRANSFERDETAILUPDATE')  THEN IT.QTY ELSE 0 END) AS AJQTY  FROM @_@INV_TRANS IT LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT  WHERE IT.OWNER_ID = A.OWNER_ID AND ISNULL(LA.VENDOR_ID,'') = A.VENDOR_ID AND IT.SKU_ID = A.SKU_ID AND LA.LOT_ATTR10 = A.LOT_ATTR10 AND ISNULL(LA.EXTERNAL_LOT,'') = ISNULL(A.EXTERNAL_LOT,'')  ) [ADJ]) AJQTY,  A.OWNER_ID,A.VENDOR_ID,A.SKU_ID,A.DESCR,A.INQTY ,A.LOT_ATTR10,A.EXTERNAL_LOT,A.OT_EXTERNAL_LOT,A.ORDER_ID,A.CONSIGNEE_ID,A.OTQTY,A.OT_DATE,A.RECEIPT_DATE,0 AS ENDQTY  FROM  (  SELECT OWNER_ID,VENDOR_ID,SKU_ID,DESCR,LOT_ATTR10,EXTERNAL_LOT,OT_EXTERNAL_LOT,CONSIGNEE_ID,RECEIPT_DATE,OT_DATE,ORDER_ID,SUM(OTQTY) AS OTQTY,  (SELECT SUM(IT.QTY) AS INQTY FROM @_@INV_TRANS IT  LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT  WHERE  IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK'  AND IT.SKU_ID = TMP.SKU_ID AND ISNULL(IT.OWNER_ID,'') = ISNULL(TMP.OWNER_ID,'') AND ISNULL(LA.VENDOR_ID,'') = TMP.VENDOR_ID AND LA.LOT_ATTR10 = TMP.LOT_ATTR10  AND ISNULL(LA.EXTERNAL_LOT,'') = ISNULL(TMP.EXTERNAL_LOT,'') AND convert(datetime, floor(convert(float, LA.RECEIPT_DATE))) = TMP.RECEIPT_DATE) INQTY  FROM(  SELECT  ISNULL(IT.OWNER_ID,'') AS OWNER_ID, ISNULL(LA.VENDOR_ID,'') AS VENDOR_ID, IT.SKU_ID,SKU.DESCR,LA.LOT_ATTR10,ISNULL(LA.EXTERNAL_LOT,'') AS EXTERNAL_LOT,LA2.EXTERNAL_LOT AS OT_EXTERNAL_LOT,  ORDERS.CONSIGNEE_ID,CONVERT(VARCHAR(20),LA.RECEIPT_DATE,23) AS RECEIPT_DATE,CONVERT(VARCHAR(30),PD.UPDATED_DATE,23) AS OT_DATE,  PD.ORDER_ID,ISNULL(PD.QTY,0) AS OTQTY,  SUM(IT.QTY) AS INQTY  FROM @_@INV_TRANS IT  LEFT JOIN @_@SKU ON SKU.SKU_ID = IT.SKU_ID AND SKU.OWNER_ID = IT.OWNER_ID  LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = IT.LOT  LEFT JOIN @_@PICK_DETAIL PD ON PD.LOT = LA.LOT AND PD.STATUS = 'SHIPPED' AND PD.UPDATED_DATE >= @begin AND PD.UPDATED_DATE <= @end  LEFT JOIN @_@LOT_ATTRIBUTE LA2 ON LA2.LOT = PD.LOT  LEFT JOIN @_@ORDERS ON ORDERS.ORDER_ID = PD.ORDER_ID  WHERE IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end  AND (IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' OR LA.LOT IN (SELECT DISTINCT LOT FROM @_@LOT_ATTRIBUTE LA2 WHERE LA2.LOT_ATTR10 = LA.LOT_ATTR10))";
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql = strSql + " AND " + sqlWhere[i].ToString();
            }
            string sql = (strSql + " GROUP BY IT.OWNER_ID,LA.VENDOR_ID,IT.SKU_ID,SKU.DESCR,LA.LOT_ATTR10,LA.EXTERNAL_LOT,LA2.EXTERNAL_LOT,PD.ORDER_ID,PD.QTY,PD.UPDATED_DATE,LA.RECEIPT_DATE,ORDERS.CONSIGNEE_ID  ) TMP GROUP BY OWNER_ID,VENDOR_ID,SKU_ID,DESCR,LOT_ATTR10,EXTERNAL_LOT,OT_EXTERNAL_LOT,CONSIGNEE_ID,RECEIPT_DATE,OT_DATE,ORDER_ID,INQTY  ) A  ) B  INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = B.OWNER_ID AND UO.[USER_ID] =  @USER_ID  ORDER BY B.OWNER_ID, B.VENDOR_ID, B.SKU_ID,B.DESCR, B.LOT_ATTR10,B.EXTERNAL_LOT,B.OT_DATE,B.RECEIPT_DATE,B.CONSIGNEE_ID ").ToString().Replace("@_@", whLoginID).Replace("@_@", whLoginID).Replace("@begin", "'" + inOutStockRptDetailQueryEntity.STARTDATETIME + "'").Replace("@end", "'" + inOutStockRptDetailQueryEntity.ENDDATETIME + "'");
            if (!inOutStockRptDetailQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, inOutStockRptDetailQueryEntity.CurrentPage, inOutStockRptDetailQueryEntity.PageSize, inOutStockRptDetailQueryEntity.SortField, inOutStockRptDetailQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInOutStockRptDetailInfo(List<string> sqlWhere, InOutStockRptDetailQueryEntity inOutStockRptDetailQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT * FROM( SELECT A.SKU_ID,B.DESCR,A.TRANS_DATE AS TransactionDate ,T.[TEXT] AS TransactionType, A.OWNER_ID,B.SKU_CLASS_ID,CASE TRANS_TYPE  WHEN 'IN' THEN  C.EXTERNAL_RECEIPT_ID  WHEN 'OT' THEN D.EXTERN_ORDER_ID  ELSE '' END AS ExternalOrderID, A.DOC_ID AS OrderID, A.QTY, A.CREATED_BY,");
            strSql.Append("(SELECT ISNULL(SUM(QTY),0) FROM @_@INV_TRANS WHERE OWNER_ID = A.OWNER_ID AND SKU_ID = A.SKU_ID AND LOT = A.LOT AND TRANS_DATE <= A.TRANS_DATE AND SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')) AS EndInginventory,");
            strSql.Append(" A.LOT_ATTR01,A.LOT_ATTR02,A.LOT_ATTR03,A.LOT_ATTR04,A.LOT_ATTR05,A.LOT_ATTR06,A.LOT_ATTR07,A.LOT_ATTR08, A.LOT_ATTR09,A.LOT_ATTR10,A.PRODUCE_DATE,A.EXPIRY_DATE,A.EXTERNAL_LOT,A.VENDOR_ID,C.RECEIPT_ID");
            strSql.Append(" FROM @_@INV_TRANS A LEFT JOIN @_@SKU B  ON A.OWNER_ID=B.OWNER_ID AND A.SKU_ID=B.SKU_ID ");
            strSql.Append(" LEFT JOIN SYSADM.TRANSLATION T ON 'TRANSTYPE.'+A.TRANS_TYPE = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" LEFT JOIN @_@RECEIPT  C ON A.DOC_ID= C.RECEIPT_ID ");
            strSql.Append(" LEFT JOIN @_@ORDERS   D ON A.DOC_ID= D.ORDER_ID ");
            strSql.Append(" WHERE A.VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID) OR A.VENDOR_ID = '' OR A.VENDOR_ID IS NULL) TEMP ");
            strSql.Append(" INNER JOIN SYSADM.USER_OWNER UO ON TEMP.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!inOutStockRptDetailQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, inOutStockRptDetailQueryEntity.CurrentPage, inOutStockRptDetailQueryEntity.PageSize, inOutStockRptDetailQueryEntity.SortField, inOutStockRptDetailQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + inOutStockRptDetailQueryEntity.SortField + " " + inOutStockRptDetailQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInOutStockRptInfo(List<string> sqlWhere, InOutStockRptQueryEntity InOutStockRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            StringBuilder strSql = new StringBuilder();
            if (InOutStockRptQuery.IsLotAttri == "1")
            {
                strSql.Append(" SELECT * FROM ( ");
                strSql.Append(" SELECT A.OWNER_ID, A.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR,s.PACK_ID, la.VENDOR_ID, ");
                strSql.Append(" il.UNIT_PRICE, la.EXTERNAL_LOT, la.PRODUCE_DATE, la.[EXPIRY_DATE], la.RECEIPT_DATE, la.LOT, ");
                strSql.Append(" la.LOT_ATTR01, la.LOT_ATTR02, la.LOT_ATTR03, la.LOT_ATTR04, la.LOT_ATTR05, ");
                strSql.Append(" la.LOT_ATTR06, la.LOT_ATTR07, la.LOT_ATTR08, la.LOT_ATTR09, la.LOT_ATTR10, ");
                strSql.Append("   SUM(A.BEGINQTY) AS BEGINQTY, SUM(A.INQTY) AS INQTY, SUM(A.OTQTY) AS OTQTY, SUM(A.AJQTY) AS AJQTY,  ");
                strSql.Append("   ISNULL(SUM(A.ENDQTY),0) AS QTY,ISNULL(SUM(A.ENDQTY),0) * s.[CUBE] AS TOTALCUBE, ISNULL(SUM(A.ENDQTY),0) * s.GROSS_WGT AS TOTALWGT ");
                strSql.Append(" FROM ( ");
                strSql.Append(" SELECT IT.LOT, IT.OWNER_ID, IT.SKU_ID, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE < @begin AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS BEGINQTY , ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE <= @end AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')   THEN IT.QTY ELSE 0 END) AS ENDQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' THEN IT.QTY ELSE 0 END) AS INQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE IN ('AJADJUSTMENTDETAILADD','AJCYCLECOUNTADD','MVTRANSFERDETAILADD','MVTRANSFERDETAILUPDATE')  THEN IT.QTY ELSE 0 END) AS AJQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' THEN IT.QTY ELSE 0 END) AS OTQTY ");
                strSql.Append(" FROM @_@INV_TRANS IT ");
                strSql.Append(" GROUP BY IT.LOT, IT.OWNER_ID, IT.SKU_ID) A ");
                strSql.Append(" LEFT JOIN @_@INV_LOT il ON il.LOT = A.LOT ");
                strSql.Append(" LEFT JOIN @_@SKU s ON s.OWNER_ID = A.OWNER_ID AND s.SKU_ID = A.SKU_ID ");
                strSql.Append(" LEFT JOIN @_@PACK p ON p.PACK_ID = s.PACK_ID ");
                strSql.Append(" LEFT JOIN @_@UOM u ON u.UOM_ID = p.PACK_UOM1 ");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE la ON la.LOT = A.LOT ");
                strSql.AppendFormat(" INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = A.OWNER_ID AND UO.[USER_ID] = '{0}' ", pubParasInfo.UserID);
                strSql.Append(" WHERE (ISNULL(A.BEGINQTY,0) <> 0 OR ISNULL(A.INQTY,0) <> 0 OR ISNULL(A.AJQTY,0) <> 0 OR ISNULL(A.OTQTY,0) <> 0 OR ISNULL(A.ENDQTY,0) <> 0) ");
                strSql.AppendFormat(" AND (LA.VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE USER_ID = '{0}') OR LA.VENDOR_ID = '' OR LA.VENDOR_ID IS NULL) ", pubParasInfo.UserID);
                for (i = 0; i < sqlWhere.Count; i++)
                {
                    strSql.Append(" AND " + sqlWhere[i].ToString());
                }
                strSql.Append(" GROUP BY A.OWNER_ID, A.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR,s.PACK_ID, la.VENDOR_ID, ");
                strSql.Append(" il.UNIT_PRICE, la.EXTERNAL_LOT, la.PRODUCE_DATE, la.[EXPIRY_DATE], la.RECEIPT_DATE, la.LOT, ");
                strSql.Append(" la.LOT_ATTR01, la.LOT_ATTR02, la.LOT_ATTR03, la.LOT_ATTR04, la.LOT_ATTR05, ");
                strSql.Append(" la.LOT_ATTR06, la.LOT_ATTR07, la.LOT_ATTR08, la.LOT_ATTR09, la.LOT_ATTR10 ");
                strSql.Append(" ) TEMP ");
            }
            else
            {
                strSql.Append(" SELECT * FROM ( ");
                strSql.Append(" SELECT A.OWNER_ID, A.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR,s.PACK_ID, la.VENDOR_ID, ");
                strSql.Append("   SUM(A.BEGINQTY) AS BEGINQTY, SUM(A.INQTY) AS INQTY, SUM(A.OTQTY) AS OTQTY, SUM(A.AJQTY) AS AJQTY,  ");
                strSql.Append("   ISNULL(SUM(A.ENDQTY),0) AS QTY,ISNULL(SUM(A.ENDQTY),0) * s.[CUBE] AS TOTALCUBE, ISNULL(SUM(A.ENDQTY),0) * s.GROSS_WGT AS TOTALWGT ");
                strSql.Append(" FROM ( ");
                strSql.Append(" SELECT IT.LOT, IT.OWNER_ID, IT.SKU_ID, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE < @begin AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS BEGINQTY  , ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE <= @end AND IT.SOURCE_TRANS_TYPE NOT IN ('Picking','PutawayMove','ConsoleMove')  THEN IT.QTY ELSE 0 END) AS ENDQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE + IT.[STATUS] = 'INRECEIPTDETAILADDOK' THEN IT.QTY ELSE 0 END) AS INQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE + IT.SOURCE_TRANS_TYPE   IN ('AJADJUSTMENTDETAILADD','AJCYCLECOUNTADD','MVTRANSFERDETAILADD','MVTRANSFERDETAILUPDATE')  THEN IT.QTY ELSE 0 END) AS AJQTY, ");
                strSql.Append("   SUM(CASE WHEN IT.TRANS_DATE >= @begin AND IT.TRANS_DATE <= @end ");
                strSql.Append("       AND IT.TRANS_TYPE+IT.STATUS = 'OTOK' THEN IT.QTY ELSE 0 END) AS OTQTY ");
                strSql.Append(" FROM @_@INV_TRANS IT ");
                strSql.Append(" GROUP BY IT.LOT, IT.OWNER_ID, IT.SKU_ID) A ");
                strSql.Append(" LEFT JOIN @_@INV_LOT il ON il.LOT = A.LOT ");
                strSql.Append(" LEFT JOIN @_@SKU s ON s.OWNER_ID = A.OWNER_ID AND s.SKU_ID = A.SKU_ID ");
                strSql.Append(" LEFT JOIN @_@PACK p ON p.PACK_ID = s.PACK_ID ");
                strSql.Append(" LEFT JOIN @_@UOM u ON u.UOM_ID = p.PACK_UOM1 ");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE la ON la.LOT = A.LOT ");
                strSql.AppendFormat(" INNER JOIN SYSADM.USER_OWNER UO ON UO.OWNER_ID = A.OWNER_ID AND UO.[USER_ID] = '{0}' ", pubParasInfo.UserID);
                strSql.Append(" WHERE (ISNULL(A.BEGINQTY,0) <> 0 OR ISNULL(A.INQTY,0) <> 0 OR ISNULL(A.AJQTY,0) <> 0 OR ISNULL(A.OTQTY,0) <> 0 OR ISNULL(A.ENDQTY,0) <> 0) ");
                strSql.AppendFormat(" AND (LA.VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE USER_ID = '{0}') OR LA.VENDOR_ID = '' OR LA.VENDOR_ID IS NULL) ", pubParasInfo.UserID);
                for (i = 0; i < sqlWhere.Count; i++)
                {
                    strSql.Append(" AND " + sqlWhere[i].ToString());
                }
                strSql.Append(" GROUP BY A.OWNER_ID, A.SKU_ID, s.DESCR, s.DESCR2, s.SKU_CLASS_ID, s.[CUBE], s.GROSS_WGT, u.UOM_DESCR, la.VENDOR_ID,s.PACK_ID ");
                strSql.Append(" ) TEMP ");
            }
            string sql = string.Empty;
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@begin", "'" + InOutStockRptQuery.STARTDATETIME + "'").Replace("@end", "'" + InOutStockRptQuery.ENDDATETIME + "'");
            if (!InOutStockRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, InOutStockRptQuery.CurrentPage, InOutStockRptQuery.PageSize, InOutStockRptQuery.SortField, InOutStockRptQuery.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + InOutStockRptQuery.SortField + " " + InOutStockRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInvLocSkyTransRptDataSet(List<string> sqlWhere, InvLocSkyTransRptQueryEntity invLocSkyTransRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder sbSQL = new StringBuilder();
            if (invLocSkyTransRptQueryEntity.SHOW_DAMAGE_5DAYS)
            {
                sbSQL.Append(" SELECT OWNER_ID, VENDOR_ID, ");
                sbSQL.Append("  SUM(CASE WHEN CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) = @BEGIN_DATE THEN ISNULL(INV_LOC,0) END) AS BEGIN_LOC, ");
                sbSQL.Append("  SUM(ISNULL(IN_LOC,0)) AS IN_LOC, SUM(ISNULL(OUT_LOC,0)) AS OUT_LOC, ");
                sbSQL.Append("  SUM(CASE WHEN CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) = @END_DATE THEN ISNULL(INV_LOC,0) END) AS END_LOC");
                sbSQL.Append(" FROM @_@DAILY_INV_LOC_SKYTRANS");
                sbSQL.Append(" WHERE CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) BETWEEN @BEGIN_DATE AND @END_DATE ");
            }
            else
            {
                sbSQL.Append(" SELECT OWNER_ID, VENDOR_ID, ");
                sbSQL.Append("  SUM(CASE WHEN CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) = @BEGIN_DATE THEN ISNULL(INV_LOC,0) - ISNULL(INV_LOC_DAMAGE,0) END) AS BEGIN_LOC, ");
                sbSQL.Append("  SUM(ISNULL(IN_LOC,0)) AS IN_LOC, SUM(ISNULL(OUT_LOC,0)) AS OUT_LOC, ");
                sbSQL.Append("  SUM(CASE WHEN CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) = @END_DATE THEN ISNULL(INV_LOC,0) - ISNULL(INV_LOC_DAMAGE,0) END) AS END_LOC");
                sbSQL.Append(" FROM @_@DAILY_INV_LOC_SKYTRANS");
                sbSQL.Append(" WHERE CONVERT(DATETIME, CONVERT(VARCHAR(10), INV_DATE, 20)) BETWEEN @BEGIN_DATE AND @END_DATE ");
            }
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sbSQL.Append(" AND " + sqlWhere[i].ToString());
            }
            sbSQL.Append(" GROUP BY OWNER_ID, VENDOR_ID ");
            string sql = sbSQL.ToString().Replace("@_@", whLoginID).Replace("@BEGIN_DATE", "'" + invLocSkyTransRptQueryEntity.BEGIN_DATE.ToString("yyyy-MM-dd") + "'").Replace("@END_DATE", "'" + invLocSkyTransRptQueryEntity.END_DATE.ToString("yyyy-MM-dd") + "'");
            if (!invLocSkyTransRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, invLocSkyTransRptQueryEntity.CurrentPage, invLocSkyTransRptQueryEntity.PageSize, invLocSkyTransRptQueryEntity.SortField, invLocSkyTransRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + invLocSkyTransRptQueryEntity.SortField + " " + invLocSkyTransRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInvoiceRpt2DataSet(List<string> sqlWhere, InvoiceRptQueryEntity invoiceRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string sql = string.Empty;
            string strWhere = string.Empty;
            string strsql = string.Empty;
            string dueFromTo = string.Empty;
            string fromTo = string.Empty;
            string descr = string.Empty;
            DateTime dt = Convert.ToDateTime(invoiceRptQueryEntity.INVOICE_DATE);
            if (dt >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")))
            {
                dt = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(-1.0);
            }
            for (i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            if (invoiceRptQueryEntity.DUE_FROM_TO.IndexOf("DueFrom") > 0)
            {
                dueFromTo = "应收账期";
                fromTo = "未收合计";
            }
            else if (invoiceRptQueryEntity.DUE_FROM_TO.IndexOf("DueTo") > 0)
            {
                dueFromTo = "应付账期";
                fromTo = "未付合计";
            }
            DateTime startDate = dt;
            DateTime endDate = dt;
            int startDays = 0;
            int endDays = 1;
            string[] billingInvoiceSetting = invoiceRptQueryEntity.BILLING_INVOICE_SETTING.Split(new char[] { ',' });
            for (i = 0; i < billingInvoiceSetting.Length; i++)
            {
                int diffDays = int.Parse(billingInvoiceSetting[i]);
                startDate = dt.AddDays((double) -diffDays);
                startDays = endDays;
                endDays = diffDays;
                descr = dueFromTo + "(" + startDays.ToString() + "-" + endDays.ToString() + "天)";
                object CS00005 = strsql;
                strsql = string.Concat(new object[] { CS00005, " (SELECT ISNULL(SUM(ID.INVOICE_AMOUNT - ID.PAY_AMOUNT),0) AS LAST_PAY_AMOUNT FROM @_@INVOICE_DETAIL ID  LEFT JOIN @_@INVOICE I ON I.INVOICE_ID = ID.INVOICE_ID   LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = I.CREATED_BY  LEFT JOIN sysadm.PREFERENCE_PROFILE PP ON PP.USER_ID = UM.USER_ID  LEFT JOIN sysadm.PREFERENCE_PROFILE_DETAIL PPD ON PPD.PREFERENCE_PROFILE_ID = PP.PREFERENCE_PROFILE_ID  AND PPD.PREFERENCE_ID = 'CURRENCY'  LEFT JOIN sysadm.PREFERENCE P ON P.PREFERENCE_ID = PPD.PREFERENCE_ID AND P.PREFERENCE_ID = 'CURRENCY'  WHERE I.BILLING_OBJECT = A.BILLING_OBJECT AND I.BILLING_OBJECT_ID = A.BILLING_OBJECT_ID AND I.DUE_FROM_TO = A.DUE_FROM_TO AND ISNULL(PPD.PREFERENCE_VALUE,'RMB') = A.PREFERENCE_VALUE  AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23)) >= '", startDate, "' AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23)) <= '", endDate, "' ) AS '", descr, "'," });
                endDate = startDate.AddDays(-1.0);
                endDays++;
                if (i == (billingInvoiceSetting.Length - 1))
                {
                    descr = dueFromTo + "(" + endDays.ToString() + "天以前)";
                    CS00005 = strsql;
                    CS00005 = string.Concat(new object[] { CS00005, " (SELECT ISNULL(SUM(ID.INVOICE_AMOUNT - ID.PAY_AMOUNT),0) AS LAST_PAY_AMOUNT FROM @_@INVOICE_DETAIL ID  LEFT JOIN @_@INVOICE I ON I.INVOICE_ID = ID.INVOICE_ID   LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = I.CREATED_BY   LEFT JOIN sysadm.PREFERENCE_PROFILE PP ON PP.USER_ID = UM.USER_ID  LEFT JOIN sysadm.PREFERENCE_PROFILE_DETAIL PPD ON PPD.PREFERENCE_PROFILE_ID = PP.PREFERENCE_PROFILE_ID  AND PPD.PREFERENCE_ID = 'CURRENCY'  LEFT JOIN sysadm.PREFERENCE P ON P.PREFERENCE_ID = PPD.PREFERENCE_ID AND P.PREFERENCE_ID = 'CURRENCY'  WHERE I.BILLING_OBJECT = A.BILLING_OBJECT AND I.BILLING_OBJECT_ID = A.BILLING_OBJECT_ID AND I.DUE_FROM_TO = A.DUE_FROM_TO AND ISNULL(PPD.PREFERENCE_VALUE,'RMB') = A.PREFERENCE_VALUE  AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23)) <= '", endDate, "' ) AS '", descr, "'," });
                    strsql = string.Concat(new object[] { CS00005, " (SELECT ISNULL(SUM(ID.INVOICE_AMOUNT - ID.PAY_AMOUNT),0) AS LAST_PAY_AMOUNT FROM @_@INVOICE_DETAIL ID  LEFT JOIN @_@INVOICE I ON I.INVOICE_ID = ID.INVOICE_ID  LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = I.CREATED_BY  LEFT JOIN sysadm.PREFERENCE_PROFILE PP ON PP.USER_ID = UM.USER_ID  LEFT JOIN sysadm.PREFERENCE_PROFILE_DETAIL PPD ON PPD.PREFERENCE_PROFILE_ID = PP.PREFERENCE_PROFILE_ID  AND PPD.PREFERENCE_ID = 'CURRENCY'  LEFT JOIN sysadm.PREFERENCE P ON P.PREFERENCE_ID = PPD.PREFERENCE_ID AND P.PREFERENCE_ID = 'CURRENCY'  WHERE I.BILLING_OBJECT = A.BILLING_OBJECT AND I.BILLING_OBJECT_ID = A.BILLING_OBJECT_ID AND I.DUE_FROM_TO = A.DUE_FROM_TO AND ISNULL(PPD.PREFERENCE_VALUE,'RMB') = A.PREFERENCE_VALUE  AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23)) <= '", dt, "') AS '", fromTo, "'" });
                }
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT I.DUE_FROM_TO,I.BILLING_OBJECT,I.BILLING_OBJECT_ID AS 结算单位,A.CREDIT_LIMIT AS 信誉额度,A.PREFERENCE_VALUE  AS 币种,");
            strSql.AppendFormat(" {0}  ", strsql);
            strSql.Append(" FROM @_@INVOICE I ");
            strSql.Append(" INNER JOIN ( ");
            strSql.Append(" SELECT I.INVOICE_ID,I.DUE_FROM_TO,I.BILLING_OBJECT,I.BILLING_OBJECT_ID,O.CREDIT_LIMIT,CASE ISNULL(PPD.PREFERENCE_VALUE,'') WHEN '' THEN 'RMB' ELSE PPD.PREFERENCE_VALUE END AS PREFERENCE_VALUE ");
            strSql.Append(" FROM @_@INVOICE I ");
            strSql.Append(" LEFT JOIN @_@OWNER O ON O.OWNER_ID =I.BILLING_OBJECT_ID AND I.BILLING_OBJECT = 'OWNER' ");
            strSql.Append(" LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = I.CREATED_BY ");
            strSql.Append(" LEFT JOIN sysadm.PREFERENCE_PROFILE PP ON PP.USER_ID = UM.USER_ID ");
            strSql.Append(" LEFT JOIN sysadm.PREFERENCE_PROFILE_DETAIL PPD ON PPD.PREFERENCE_PROFILE_ID = PP.PREFERENCE_PROFILE_ID AND PPD.PREFERENCE_ID = 'CURRENCY' ");
            strSql.Append(" LEFT JOIN sysadm.PREFERENCE P ON P.PREFERENCE_ID = PPD.PREFERENCE_ID AND P.PREFERENCE_ID = 'CURRENCY' ");
            strSql.Append(" INNER JOIN ( ");
            strSql.Append(" SELECT USER_ID,OWNER_ID AS BILLING_OBJECT_ID,'Owner' AS BILLING_OBJECT FROM SYSADM.USER_OWNER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,VENDOR_ID AS BILLING_OBJECT_ID,'Vendor' AS BILLING_OBJECT FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,CUSTOMER_ID AS BILLING_OBJECT_ID,'Customer' AS BILLING_OBJECT FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,CARRIER_ID AS BILLING_OBJECT_ID,'Carrier' AS BILLING_OBJECT FROM SYSADM.USER_CARRIER WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" UNION ");
            strSql.Append(" SELECT USER_ID,BILLINGENTITY_ID AS BILLING_OBJECT_ID,'BillingEntity' AS BILLING_OBJECT FROM SYSADM.USER_BILLINGENTITY WHERE [USER_ID] = @USER_ID ");
            strSql.Append(" ) BO ON BO.BILLING_OBJECT_ID = I.BILLING_OBJECT_ID AND BO.BILLING_OBJECT = I.BILLING_OBJECT ");
            strSql.Append(" WHERE I.STATUS <> 'CLOSED' AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23)) <= @BILLING_DATE ) A ON A.BILLING_OBJECT_ID = I.BILLING_OBJECT_ID AND A.BILLING_OBJECT = I.BILLING_OBJECT AND I.DUE_FROM_TO = A.DUE_FROM_TO ");
            strSql.AppendFormat(" WHERE I.STATUS <> 'CLOSED' AND CONVERT(DATETIME,CONVERT(VARCHAR(20),I.BILLING_DATE,23))<= @BILLING_DATE {0}  ", strWhere);
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@BILLING_DATE", "'" + dt.ToString() + "'");
            if (!invoiceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, invoiceRptQueryEntity.CurrentPage, invoiceRptQueryEntity.PageSize, invoiceRptQueryEntity.SortField, invoiceRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + invoiceRptQueryEntity.SortField + " " + invoiceRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetInvoiceRptDataSet(List<string> sqlWhere, InvoiceRptQueryEntity invoiceRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT OWNER.OWNER_ID,OWNER.COMPANY,IND.STATEMENT_ID,IND.DESCR,CONVERT(VARCHAR(20),I.BILLING_DATE,23) AS BILLING_DATE,I.INVOICE_ID,  ");
            strSql.Append("  I.CREATED_BY,UM.[USER_NAME],I.STATUS,T.[TEXT] AS STATUS_D,I.IS_INVOICE_SUBMIT,I.IS_AMOUNT_SUBMIT,SUM(IND.INVOICE_AMOUNT) AS INVOICE_AMOUNT,'' AS USER_1  ");
            strSql.Append("  FROM @_@INVOICE_DETAIL IND ");
            strSql.Append("  LEFT JOIN @_@INVOICE I ON I.INVOICE_ID = IND.INVOICE_ID  ");
            strSql.Append("  LEFT JOIN @_@OWNER ON OWNER.OWNER_ID = I.BILLING_OBJECT_ID ");
            strSql.Append("  LEFT JOIN sysadm.TRANSLATION T ON 'InvoiceStatus.'+I.STATUS = T.ITEM_ID  AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON OWNER.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  ");
            strSql.Append("  LEFT JOIN SYSADM.USER_MST UM ON UM.USER_ID = I.CREATED_BY  ");
            strSql.AppendFormat("  WHERE  1=1   {0}  ", strWhere);
            strSql.Append("  GROUP BY OWNER.OWNER_ID,OWNER.COMPANY,IND.STATEMENT_ID,IND.DESCR,I.BILLING_DATE,I.INVOICE_ID,I.CREATED_BY,UM.[USER_NAME],I.STATUS,T.[TEXT],I.IS_INVOICE_SUBMIT,I.IS_AMOUNT_SUBMIT  ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!invoiceRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), invoiceRptQueryEntity.CurrentPage, invoiceRptQueryEntity.PageSize, invoiceRptQueryEntity.SortField, invoiceRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + invoiceRptQueryEntity.SortField + " " + invoiceRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetLoadingRptDataSet(List<string> sqlWhere, LoadingRptQueryEntity loadingRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT * FROM (");
            strSql.Append(" SELECT DISTINCT BOL.BOL_ID, BD.CARRIER, BOL.CREATED_DATE, BOL.QTY, BOL.GROSS_WEIGHT, BOL.[CUBE], BOL.FREIGHT_SELF, BOL.FREIGHT_DEALER, BOL.PAID, BD.ACTUAL_EQUIPMENT, BOL.REMARK ");
            strSql.Append(" FROM @_@BOL BOL LEFT JOIN @_@BOL_DETAIL BD ON BD.BOL_ID = BOL.BOL_ID ");
            strSql.Append("   LEFT JOIN @_@DELIVERY_ORDER DO ON DO.DELIVERY_ORDER_ID = BD.DELIVERY_ID ");
            strSql.Append(" WHERE 1 = 1 ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" ) TMP");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            if (!loadingRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, loadingRptQueryEntity.CurrentPage, loadingRptQueryEntity.PageSize, loadingRptQueryEntity.SortField, loadingRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + loadingRptQueryEntity.SortField + " " + loadingRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetLocationRptInfo(List<string> sqlWhere, LocationRptQueryEntity locationRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = "SELECT DISTINCT LOC.LOC AS LOC,LOC.CUBIC_CAPACITY AS CUBIC_CAPACITY,TEMP.ONHAND_CUBE AS CUBE_ONHAND,LOC.ZONE_ID AS ZONE_ID,  LOC.LOC_USAGE AS LOC_USAGE,  T.[TEXT] AS T_LOC_USAGE,  LOC.ABC AS ABC,  T3.[TEXT] AS T_ABC,  LOC.LOGICAL_LOC AS LOGICAL_LOC,  LOC.LOC_FLAG AS LOC_FLAG,  T1.[TEXT] AS T_LOC_FLAG,  LOC.IS_MULTI_SKU AS IS_MULTI_SKU,LOC.IS_MULTI_LOT AS IS_MULTI_LOT,LOC.CHECK_DIG AS CHECK_DIG, CASE LOC.CUBIC_CAPACITY WHEN 0 THEN '0' ELSE CAST((TEMP.ONHAND_CUBE / LOC.CUBIC_CAPACITY * 100) AS VARCHAR) END + '%' AS CUBE_ONHAND_PERCENTAGE, LOC.CUBIC_CAPACITY-TEMP.ONHAND_CUBE AS AVAILABLE_CUBE,  LOC.STATUS AS STATUS ,  T2.[TEXT] AS T_STATUS  FROM @_@LOCATION LOC  LEFT JOIN @_@INV_SKU_LOC ISL ON LOC.LOC = ISL.LOC  LEFT JOIN @_@SKU SKU ON ISL.OWNER_ID = SKU.OWNER_ID AND ISL.SKU_ID = SKU.SKU_ID LEFT JOIN (SELECT ISL.LOC,SUM(ISL.QTY * SKU.[CUBE]) AS ONHAND_CUBE FROM @_@INV_SKU_LOC ISL LEFT JOIN @_@SKU SKU ON ISL.OWNER_ID = SKU.OWNER_ID AND ISL.SKU_ID = SKU.SKU_ID GROUP BY ISL.LOC)   TEMP ON ISL.LOC = TEMP.LOC  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = LOC.LOC_USAGE AND SCD.SYS_CODE_TYPE = 'LocUsage'  LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = LOC.LOC_FLAG AND SCD2.SYS_CODE_TYPE = 'LocFlag'  LEFT JOIN @_@SYS_CODE_DETAIL SCD3 ON SCD3.SYS_CODE = LOC.STATUS AND SCD3.SYS_CODE_TYPE = 'LocFlag'  LEFT JOIN @_@SYS_CODE_DETAIL SCD4 ON SCD4.SYS_CODE = LOC.ABC AND SCD3.SYS_CODE_TYPE = 'ABC'  LEFT JOIN sysadm.TRANSLATION T ON 'LocUsage.'+LOC.LOC_USAGE = T.ITEM_ID      AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T1 ON 'LocFlag.'+LOC.LOC_FLAG = T1.ITEM_ID      AND  T1.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T1.LANG+'-'+T1.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T2 ON 'LocFlag.'+LOC.STATUS = T2.ITEM_ID     AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T3 ON 'ABC.'+LOC.ABC = T3.ITEM_ID      AND  T3.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T3.LANG+'-'+T3.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON ISL.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!locationRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, locationRptQuery.CurrentPage, locationRptQuery.PageSize, locationRptQuery.SortField, locationRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + locationRptQuery.SortField + " " + locationRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetOnTheWayOrderRptDataSet(List<string> sqlWhere, OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.PO_ID AS PO_ID,A.PO_DATE AS PO_DATE,A.REQUEST_DELIVERY_DATE AS REQUEST_DELIVERY_DATE,A.VENDOR_ID AS VENDOR_ID,A.OTHER_REF AS OTHER_REF,A.EXTERNAL_PO_ID AS EXTERNAL_PO_ID, T2.[TEXT] AS PO_TYPE,T.[TEXT] AS STATUS,A.OWNER_ID AS OWNER_ID,B.SKU_ID AS SKU_ID,B.SKU_DESC AS SKU_DESC, ");
            strSql.Append("  B.ORDERED_QTY-RECEIVED_QTY AS QTY,B.PACK_ID AS PACK_ID,B.UOM_ID AS UOM_ID,D.UOM_DESCR AS UOM_DESCR,B.UNIT_PRICE AS UNIT_PRICE,B.TOTAL_PRICE AS TOTAL_PRICE, B.TOTAL_CUBE AS TOTAL_CUBE,B.TOTAL_GROSS_WEIGHT AS TOTAL_GROSS_WEIGHT,B.REMARK AS REMARK,C.SKU_CLASS_ID AS SKU_CLASS_ID,C.SKU_GROUP AS SKU_GROUP,C.DESCR2 AS SKU_DESCR2, C.UDF2 AS SKU_UDF2,A.CREATED_BY AS CREATED_BY,A.CREATED_DATE AS CREATED_DATE,A.UPDATED_BY AS UPDATED_BY,A.UPDATED_DATE AS UPDATED_DATE ");
            strSql.Append("  FROM @_@PURCHASE_ORDER A  INNER JOIN  @_@PURCHASE_ORDER_DETAIL B ON A.PO_ID =B.PO_ID  INNER JOIN @_@SKU C ON B.OWNER_ID =C.OWNER_ID AND B.SKU_ID = C.SKU_ID  INNER JOIN @_@UOM D ON B.UOM_ID=D.UOM_ID");
            strSql.Append("  LEFT JOIN sysadm.TRANSLATION T ON 'PoStatus.'+A.STATUS = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append("  LEFT JOIN sysadm.TRANSLATION T2 ON 'PoType.'+A.PO_TYPE = T2.ITEM_ID  AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY =@LANGUAGE ");
            strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON A.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
            string sql = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            sql = (strSql.ToString() + sql).Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'").Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            if (!onTheWayOrderRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, onTheWayOrderRptQueryEntity.CurrentPage, onTheWayOrderRptQueryEntity.PageSize, onTheWayOrderRptQueryEntity.SortField, onTheWayOrderRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + onTheWayOrderRptQueryEntity.SortField + " " + onTheWayOrderRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetOperationLogDataSet(List<string> sqlWhere, OperationLogQueryEntity operationLogQueryEntity, List<string> whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            StringBuilder strsql = new StringBuilder();
            strsql.Append(" SELECT DISTINCT A.ROWID,A.WH_ID,A.[USER_ID],A.LOG_DATE,A.OPERATION_DESCR,A.UDF1,A.UDF2,A.UDF3,A.UDF4,A.UDF5,B.WH_DB_DESC,B.DB_LOGIN_ID ");
            strsql.Append(" FROM sysadm.OPERATION_LOG A LEFT OUTER JOIN sysadm.DB_CONFIG B ON A.WH_ID = B.WH_DB_ID ");
            strsql.Append(" WHERE 1=1 ");
            for (i = 0; i < sqlWhere.Count; i++)
            {
                strsql.Append(" AND " + sqlWhere[i]);
            }
            string wh_id = string.Empty;
            for (i = 0; i < whLoginID.Count; i++)
            {
                wh_id = wh_id + ((i == 0) ? "" : ",") + "'" + whLoginID[i] + "'";
            }
            if (!string.IsNullOrEmpty(wh_id))
            {
                strsql.Append(" AND B.DB_LOGIN_ID IN (" + wh_id + ")");
            }
            string StrSql = strsql.ToString();
            if (!operationLogQueryEntity.IsGetAll)
            {
                StrSql = PagingHelper.GetPagingSQL(strsql.ToString(), operationLogQueryEntity.CurrentPage, operationLogQueryEntity.PageSize, operationLogQueryEntity.SortField, operationLogQueryEntity.SortDirection);
            }
            else
            {
                StrSql = StrSql + " ORDER BY " + operationLogQueryEntity.SortField + " " + operationLogQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, StrSql);
        }

        public DataSet GetOperatorWorkRptDataSet(List<string> sqlWhere, OperatorWorkRptQueryEntity operatorWorkRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.[USER_NAME],SUM(A.RECEIPTCOUNT) AS RECEIPTCOUNT,SUM(A.ORDERCOUNT) AS ORDERCOUNT, ");
            strSql.Append(" SUM(A.MOVEMENTCOUNT) AS MOVEMENTCOUNT,SUM(A.RECEIPTCOUNT+A.ORDERCOUNT+A.MOVEMENTCOUNT) AS TOTALCOUNT  ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT U.[USER_NAME],COUNT(*) AS RECEIPTCOUNT,0 AS ORDERCOUNT,0 AS MOVEMENTCOUNT FROM SYSADM.USER_MST U ");
            strSql.Append(" INNER JOIN @_@RECEIPT C ON U.[USER_ID]=C.CREATED_BY ");
            strSql.Append("  WHERE 1=1 ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY U.[USER_NAME] ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT U.[USER_NAME],0 AS RECEIPTCOUNT, COUNT(*) AS ORDERCOUNT,0 AS MOVEMENTCOUNT FROM SYSADM.USER_MST U ");
            strSql.Append(" INNER JOIN @_@ORDERS C ON U.[USER_ID]=C.CREATED_BY ");
            strSql.Append("  WHERE 1=1 ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY U.[USER_NAME] ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT U.[USER_NAME],0 AS RECEIPTCOUNT, 0 AS ORDERCOUNT,COUNT(*) AS MOVEMENTCOUNT FROM SYSADM.USER_MST U ");
            strSql.Append(" INNER JOIN @_@MOVEMENT C ON U.[USER_ID]=C.CREATED_BY ");
            strSql.Append("  WHERE 1=1 ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" GROUP BY U.[USER_NAME] ");
            strSql.Append(" ) A GROUP BY A.[USER_NAME] ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!operatorWorkRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), operatorWorkRptQueryEntity.CurrentPage, operatorWorkRptQueryEntity.PageSize, operatorWorkRptQueryEntity.SortField, operatorWorkRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + operatorWorkRptQueryEntity.SortField + " " + operatorWorkRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetOwnerTransferRptDataSet(List<string> sqlWhere, OwnerTransferRptQueryEntity ownerTransferRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string strSql = " SELECT A.LINE_ID,A.TRANSFER_ID,A.TRANSFER_DATE,A.FROM_OWNER_ID,A.FROM_SKU_ID,FC.DESCR AS FROM_DESCR,A.FROM_PACK_ID,A.TO_OWNER_ID,  A.TO_SKU_ID,TC.DESCR AS TO_DESCR ,A.TO_PACK_ID,  B.QTY,A.REMARK,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.EXTERNAL_LOT AS EXTERNAL_LOT,LA.VENDOR_ID AS VENDOR_ID,LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03, LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05,LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08,LA.LOT_ATTR09 AS LOT_ATTR09,LA.LOT_ATTR10 AS LOT_ATTR10 FROM @_@OWNER_TRANSFER_DETAIL A INNER JOIN  @_@TRANSFER_PICK_DETAIL B  ON A.TRANSFER_ID = B.ORDER_ID AND A.LINE_ID = B.ORDER_LINE_ID INNER JOIN @_@SKU FC ON A.FROM_SKU_ID = FC.SKU_ID AND A.FROM_OWNER_ID = FC.OWNER_ID  INNER JOIN @_@SKU TC ON A.TO_SKU_ID = TC.SKU_ID AND A.TO_OWNER_ID = TC.OWNER_ID LEFT JOIN @_@LOT_ATTRIBUTE LA  ON B.LOT = LA.LOT  INNER JOIN SYSADM.USER_OWNER UO ON A.FROM_OWNER_ID = UO.OWNER_ID  AND UO.[USER_ID] = @USER_ID  INNER JOIN SYSADM.USER_OWNER UOR ON A.TO_OWNER_ID=UOR.OWNER_ID  AND UOR.[USER_ID] = @USER_ID ";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!ownerTransferRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, ownerTransferRptQueryEntity.CurrentPage, ownerTransferRptQueryEntity.PageSize, ownerTransferRptQueryEntity.SortField, ownerTransferRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + ownerTransferRptQueryEntity.SortField + " " + ownerTransferRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetPhysicalCountReportDataSet(List<string> sqlWhere, PhysicalCountDiffRptQueryEntity physicalCountDiffRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            if (physicalCountDiffRptQueryEntity.ShowLot == "N")
            {
                strSql.Append("  SELECT  PT.LOC AS LOC,PT.SKU_ID AS SKU_ID,PT.OWNER_ID AS OWNER_ID,S.DESCR AS DESCR,P.PACK_ID AS SKU_STYLE,PT.SYS_QTY AS SYS_QTY,PT.RECOUNT_QTY  AS RECOUNT_QTY,PT.ADJ_QTY AS ADJ_QTY,U.UOM_DESCR AS UOM_ID,PT.LPN_ID AS LPN_ID");
                strSql.Append("  FROM @_@PHYSICAL_TAG PT   ");
                strSql.Append("  JOIN @_@SKU S ON S.SKU_ID=PT.SKU_ID AND S.OWNER_ID=PT.OWNER_ID ");
                strSql.Append("  LEFT JOIN @_@PACK P ON S.PACK_ID=P.PACK_ID ");
                strSql.Append("  LEFT JOIN @_@UOM U ON P.PACK_UOM1=U.UOM_ID  ");
                strSql.Append("  INNER JOIN SYSADM.USER_OWNER G ON PT.OWNER_ID = G.OWNER_ID  AND G.[USER_ID] = @USER_ID  ");
                strSql.Append("  WHERE PT.ADJ_QTY != 0 AND PT.STATUS='Closed' ");
            }
            else
            {
                strSql.Append("  SELECT  PT.LOC AS LOC,PT.SKU_ID AS SKU_ID,PT.OWNER_ID AS OWNER_ID,S.DESCR AS DESCR,P.PACK_ID AS SKU_STYLE,PT.SYS_QTY AS SYS_QTY,PT.RECOUNT_QTY  AS RECOUNT_QTY,PT.ADJ_QTY AS ADJ_QTY,U.UOM_DESCR AS UOM_ID,PT.LPN_ID AS LPN_ID,PT.LOT AS LOT,LA.EXTERNAL_LOT AS EXTERNAL_LOT,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.VENDOR_ID AS VENDOR_ID,LA.RECEIPT_DATE AS RECEIPT_DATE,LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03,LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05,LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,LA.LOT_ATTR10 AS LOT_ATTR10");
                strSql.Append("  FROM @_@PHYSICAL_TAG PT   ");
                strSql.Append("  JOIN @_@SKU S ON S.SKU_ID=PT.SKU_ID AND S.OWNER_ID=PT.OWNER_ID ");
                strSql.Append("  LEFT JOIN @_@PACK P ON S.PACK_ID=P.PACK_ID ");
                strSql.Append("  LEFT JOIN @_@UOM U ON P.PACK_UOM1=U.UOM_ID  ");
                strSql.Append("  LEFT JOIN @_@LOT_ATTRIBUTE LA ON PT.LOT=LA.LOT ");
                strSql.Append("  LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
                strSql.Append("  INNER JOIN SYSADM.USER_OWNER G ON PT.OWNER_ID = G.OWNER_ID  AND G.[USER_ID] = @USER_ID  ");
                strSql.Append("  WHERE PT.ADJ_QTY != 0 AND PT.STATUS='Closed' ");
            }
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!physicalCountDiffRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, physicalCountDiffRptQueryEntity.CurrentPage, physicalCountDiffRptQueryEntity.PageSize, physicalCountDiffRptQueryEntity.SortField, physicalCountDiffRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + physicalCountDiffRptQueryEntity.SortField + " " + physicalCountDiffRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetPhysicalCountReportList(List<string> sqlWhere, PhysicalCountRptQueryEntity physicalCountRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string StrGroupby = string.Empty;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT L.LOC,B.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,A.SKU_ID,B.DESCR,C.PACK_ID,SUM(A.QTY) AS INV_QTY,U.UOM_DESCR,A.LPN_ID,B.SKU_STYLE ");
            if (physicalCountRptQueryEntity.ShowLot == "Y")
            {
                strSql.Append(",A.LOT,D.EXTERNAL_LOT,D.PRODUCE_DATE,D.EXPIRY_DATE,D.VENDOR_ID,D.RECEIPT_DATE,D.LOT_ATTR01,D.LOT_ATTR02,D.LOT_ATTR03,D.LOT_ATTR04,D.LOT_ATTR05,D.LOT_ATTR06,D.LOT_ATTR07,D.LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,D.LOT_ATTR10");
                StrGroupby = ",A.LOT,D.EXTERNAL_LOT,D.PRODUCE_DATE,D.EXPIRY_DATE,D.VENDOR_ID,D.RECEIPT_DATE,D.LOT_ATTR01,D.LOT_ATTR02,D.LOT_ATTR03,D.LOT_ATTR04,D.LOT_ATTR05,D.LOT_ATTR06,D.LOT_ATTR07,D.LOT_ATTR08,LAC.DESCR,D.LOT_ATTR10 ";
            }
            strSql.Append(" FROM @_@LOCATION L LEFT JOIN @_@INV_LOT_LOC_LPN A ON A.LOC=L.LOC LEFT JOIN @_@LOT_ATTRIBUTE D ON D.LOT=A.LOT ");
            strSql.Append(" LEFT JOIN @_@SKU B ON A.SKU_ID=B.SKU_ID AND A.OWNER_ID=B.OWNER_ID LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = B.OWNER_ID AND SC.SKU_CLASS_ID = B.SKU_CLASS_ID ");
            strSql.Append(" LEFT JOIN @_@PACK C ON B.PACK_ID=C.PACK_ID LEFT JOIN @_@UOM U ON C.PACK_UOM1=U.UOM_ID ");
            strSql.AppendFormat("  INNER JOIN SYSADM.USER_OWNER G ON (A.OWNER_ID = G.OWNER_ID OR A.OWNER_ID IS NULL) AND (G.[USER_ID] = '{0}'  OR A.OWNER_ID IS NULL) ", pubParasInfo.UserID);
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON D.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            sql = sql + " GROUP BY L.LOC,B.SKU_CLASS_ID,SC.DESCR,A.SKU_ID,B.DESCR,C.PACK_ID,U.UOM_DESCR,A.LPN_ID,B.SKU_STYLE " + StrGroupby;
            if (!physicalCountRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, physicalCountRptQueryEntity.CurrentPage, physicalCountRptQueryEntity.PageSize, physicalCountRptQueryEntity.SortField, physicalCountRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'") + " ORDER BY " + physicalCountRptQueryEntity.SortField + " " + physicalCountRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetPickPickingRptInfo(List<string> sqlWhere, PickingRptQueryEntity PickingRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = string.Empty;
            string sqlOrderType = !string.IsNullOrEmpty(PickingRptQuery.ORDER_TYPE) ? (" AND  ORDER_TYPE " + PickingRptQuery.ORDER_TYPE) : "";
            string strSqlWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSqlWhere = strSqlWhere + " AND " + sqlWhere[i].ToString();
            }
            if (PickingRptQuery.IS_GROUP == "Y")
            {
                strSql = " SELECT TEMP.ORDER_TYPE, TEMP.STATUS,TEMP.WAVE_ID, TEMP.ORDER_ID, TEMP.EXTERN_ORDER_ID, TEMP.REFERENCE_NUM, TEMP.OWNER_ID, TEMP.PACK_ID, TEMP.ORDER_LINE_ID, TEMP.ORDER_DATE,  TEMP.ORIGINAL_QTY, SUM(TEMP.QTY) AS QTY,TEMP.ORIGINAL_QTY - ISNULL(SUM(TEMP.QTY),0) AS DIFF_QTY,TEMP.REQUESTED_SHIP_DATE,  TEMP.ACTUAL_SHIP_DATE,TEMP.CREATED_BY,TEMP.UOM_DESCR, TEMP.CREATED_DATE,  TEMP.SKU_ID,  TEMP.SKU_DESCR, TEMP.SKU_CLASS_ID,    TEMP.BARCODE,    SUM(TEMP.TOTAL_GROSS_WGT) AS TOTAL_GROSS_WGT, SUM(TEMP.TOTAL_NET_WGT) AS TOTAL_NET_WGT,    SUM(TOTAL_CUBE) AS TOTAL_CUBE,   TEMP.CUSTOMER_ID,   TEMP.CUST_ADDRESS    FROM ( SELECT DISTINCT T2.[TEXT] AS ORDER_TYPE, T.[TEXT] AS STATUS, WD.WAVE_ID, ORDERS.ORDER_ID,  ORDERS.EXTERN_ORDER_ID,   ORDERS.REFERENCE_NUM,OD.ORIGINAL_QTY, PD.OWNER_ID,   ORDERS.ORDER_DATE,SKU.PACK_ID,  ORDERS.REQUESTED_SHIP_DATE, ORDERS.ACTUAL_SHIP_DATE, ORDERS.CREATED_BY,U.UOM_DESCR, ORDERS.CREATED_DATE, PD.ORDER_LINE_ID,TD.RELEASE_DATE,  PD.SKU_ID,  SKU.DESCR AS SKU_DESCR, SKU.SKU_CLASS_ID,SKU.ZONE_ID, PD.QTY as qty, PD.LPN_ID, PD.UOM_ID,  SKU.B_UDF1 AS BARCODE,   PD.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT, PD.QTY * SKU.NET_WGT AS TOTAL_NET_WGT,PD.QTY * SKU.[CUBE] AS TOTAL_CUBE,    ORDERS.CONSIGNEE_ID AS CUSTOMER_ID,   CUSTOMER.COMPANY AS CUST_NAME, CUSTOMER.ADDRESS AS CUST_ADDRESS FROM @_@PICK_DETAIL AS PD   LEFT JOIN @_@ORDERS AS ORDERS ON PD.ORDER_ID = ORDERS.ORDER_ID  LEFT JOIN @_@WAVE_DETAIL WD ON WD.ORDER_ID = ORDERS.ORDER_ID  LEFT JOIN @_@ORDER_DETAIL AS OD ON PD.ORDER_ID = OD.ORDER_ID AND PD.ORDER_LINE_ID = OD.LINE_ID  LEFT JOIN @_@SKU AS SKU ON PD.OWNER_ID = SKU.OWNER_ID AND PD.SKU_ID = SKU.SKU_ID  LEFT JOIN @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID  LEFT JOIN @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1  LEFT JOIN @_@CUSTOMER AS CUSTOMER ON ORDERS.CONSIGNEE_ID = CUSTOMER.CUSTOMER_ID   LEFT JOIN @_@TASK_DETAIL AS TD ON PD.PICK_DETAIL_ID = TD.PICK_DETAIL_ID  LEFT JOIN @_@LOT_ATTRIBUTE AS LA ON PD.LOT = LA.LOT   LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = PD.STATUS AND SCD.SYS_CODE_TYPE = 'PickDetailStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = ORDERS.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType' LEFT JOIN sysadm.TRANSLATION T ON 'PickDetailStatus.'+PD.STATUS = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+ORDERS.TYPE = T2.ITEM_ID AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON ORDERS.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE 1 = 1 " + strSqlWhere + " ) TEMP   WHERE (CUSTOMER_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR CUSTOMER_ID IS NULL OR CUSTOMER_ID = '' OR CUSTOMER_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID)) " + sqlOrderType;
            }
            else
            {
                strSql = " SELECT DISTINCT * FROM (   SELECT DISTINCT PD.PICK_DETAIL_ID, T2.[TEXT] AS ORDER_TYPE, T.[TEXT] AS STATUS, WD.WAVE_ID, ORDERS.ORDER_ID,  ORDERS.EXTERN_ORDER_ID,  ORDERS.REFERENCE_NUM,  PD.OWNER_ID,    ORDERS.ORDER_DATE,  ORDERS.REQUESTED_SHIP_DATE, ORDERS.ACTUAL_SHIP_DATE, ORDERS.CREATED_BY, ORDERS.CREATED_DATE, PD.ORDER_LINE_ID,TD.RELEASE_DATE, CASE PD.STATUS WHEN 'NEW' THEN NULL   ELSE PD.UPDATED_DATE END AS PICK_DETAIL_CONFIRM_DATE,  PD.SKU_ID,  SKU.DESCR AS SKU_DESCR, SKU.SKU_CLASS_ID,SKU.ZONE_ID, PD.QTY,  PD.UOM_ID,   PD.LOC, PD.LPN_ID, LAC.DESCR AS SKU_PROPERTY, SKU.B_UDF1 AS BARCODE,    PD.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT, PD.QTY * SKU.NET_WGT AS TOTAL_NET_WGT,   PD.QTY * SKU.[CUBE] AS TOTAL_CUBE,   ORDERS.CONSIGNEE_ID AS CUSTOMER_ID,   CUSTOMER.COMPANY AS CUST_NAME, CUSTOMER.ADDRESS AS CUST_ADDRESS, LA.LOT_ATTR01,   LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08,  LAC.DESCR AS LOT_ATTR09,   LA.LOT_ATTR10,  LA.PRODUCE_DATE, LA.EXPIRY_DATE, LA.EXTERNAL_LOT,LA.RECEIPT_DATE, VR.VENDOR_ID, VR.COMPANY AS VENDOR_COMPANY ,ORDERS.REMARK AS REMARK,OD.ORIGINAL_QTY   FROM @_@PICK_DETAIL AS PD LEFT JOIN   @_@ORDERS AS ORDERS ON PD.ORDER_ID = ORDERS.ORDER_ID   LEFT JOIN @_@ORDER_DETAIL AS OD ON PD.ORDER_ID = OD.ORDER_ID AND PD.ORDER_LINE_ID = OD.LINE_ID  LEFT OUTER JOIN  @_@WAVE_DETAIL WD ON WD.ORDER_ID = ORDERS.ORDER_ID LEFT JOIN  @_@SKU AS SKU ON PD.OWNER_ID = SKU.OWNER_ID AND PD.SKU_ID = SKU.SKU_ID LEFT OUTER JOIN   @_@CUSTOMER AS CUSTOMER ON ORDERS.CONSIGNEE_ID = CUSTOMER.CUSTOMER_ID LEFT OUTER JOIN   @_@TASK_DETAIL AS TD ON PD.PICK_DETAIL_ID = TD.PICK_DETAIL_ID LEFT OUTER JOIN   @_@LOT_ATTRIBUTE AS LA ON PD.LOT = LA.LOT   LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = PD.STATUS AND SCD.SYS_CODE_TYPE = 'PickDetailStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = ORDERS.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType' LEFT JOIN sysadm.TRANSLATION T ON 'PickDetailStatus.'+PD.STATUS = T.ITEM_ID           AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+ORDERS.TYPE = T2.ITEM_ID           AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE LEFT JOIN @_@VENDOR AS VR ON LA.VENDOR_ID = VR.VENDOR_ID INNER JOIN SYSADM.USER_OWNER UO ON ORDERS.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'  WHERE 1 = 1 " + strSqlWhere + " ) TEMP   WHERE (CUSTOMER_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR CUSTOMER_ID IS NULL OR CUSTOMER_ID = '' OR CUSTOMER_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID)) " + sqlOrderType;
            }
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            if (PickingRptQuery.IS_GROUP == "Y")
            {
                sql = sql + " GROUP BY  TEMP.ORDER_TYPE, TEMP.STATUS,TEMP.WAVE_ID, TEMP.ORDER_ID, TEMP.EXTERN_ORDER_ID, TEMP.REFERENCE_NUM, TEMP.OWNER_ID,TEMP.PACK_ID, TEMP.ORDER_LINE_ID, TEMP.ORDER_DATE, TEMP.ORIGINAL_QTY,TEMP.REQUESTED_SHIP_DATE,  TEMP.ACTUAL_SHIP_DATE,TEMP.CREATED_BY,TEMP.UOM_DESCR, TEMP.CREATED_DATE,  TEMP.SKU_ID,  TEMP.SKU_DESCR, TEMP.SKU_CLASS_ID,  TEMP.BARCODE,  TEMP.CUSTOMER_ID,   TEMP.CUST_ADDRESS   ";
            }
            if (!PickingRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, PickingRptQuery.CurrentPage, PickingRptQuery.PageSize, PickingRptQuery.SortField, PickingRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + PickingRptQuery.SortField + " " + PickingRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetPurchasePlanRptDataSet(List<string> sqlWhere, PurchasePlanRptQueryEntity purchasePlanRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("    SELECT INV.OWNER_ID,INV.SKU_ID,INV.DESCR,INV.SKU_CLASS_ID,INV.MIN_QTY,INV.MAX_QTY,INV.REORDER_QTY,INV.PACK_ID,INV.UOM_DESCR,ISNULL(SUM(INV.INVQTY),0) AS INVQTY,ISNULL(SUM(POD.RECEIVED_QTY),0) AS RECEIVED_QTY ,ISNULL(SUM(POD.ORDERED_QTY), 0) AS ORDERED_QTY,ISNULL(SUM(POD.ORDERED_QTY)-SUM(POD.RECEIVED_QTY),0) AS TRANSIT_QTY FROM  ");
            strSql.Append("   (SELECT S.OWNER_ID,S.SKU_ID,S.DESCR,S.SKU_CLASS_ID,S.MIN_QTY,S.MAX_QTY,S.REORDER_QTY,SUM(INV.QTY) AS INVQTY,S.PACK_ID,U.UOM_DESCR ");
            strSql.Append("    FROM  @_@SKU S ");
            strSql.Append("  LEFT JOIN @_@PACK P ON P.PACK_ID = S.PACK_ID ");
            strSql.Append("  LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1 ");
            strSql.Append("  LEFT JOIN  @_@INV_LOT INV ON S.OWNER_ID=INV.OWNER_ID AND S.SKU_ID = INV.SKU_ID  ");
            strSql.Append("    INNER JOIN SYSADM.USER_OWNER UO ON S.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID  WHERE S.REORDER_QTY >0 AND S.IS_ACTIVE='Y'");
            strSql.Append("    GROUP BY  S.OWNER_ID,S.SKU_ID,S.DESCR,S.SKU_CLASS_ID,S.MIN_QTY,S.MAX_QTY,S.REORDER_QTY,S.PACK_ID,U.UOM_DESCR ) INV ");
            strSql.Append("   LEFT JOIN  @_@PURCHASE_ORDER_DETAIL POD ON INV.OWNER_ID=POD.OWNER_ID AND INV.SKU_ID = POD.SKU_ID AND (POD.STATUS ='NEW' OR POD.STATUS='INRECEIVING') ");
            string sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE  " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            sql = sql + " GROUP BY INV.OWNER_ID,INV.SKU_ID,INV.DESCR,INV.SKU_CLASS_ID,INV.MIN_QTY,INV.MAX_QTY,INV.REORDER_QTY,INV.PACK_ID,INV.UOM_DESCR  HAVING  ISNULL(SUM(INV.INVQTY),0)+(ISNULL(SUM(POD.ORDERED_QTY),0)-ISNULL(SUM(POD.RECEIVED_QTY),0))-ISNULL(INV.MIN_QTY,0 )<=0 ";
            if (!purchasePlanRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, purchasePlanRptQueryEntity.CurrentPage, purchasePlanRptQueryEntity.PageSize, purchasePlanRptQueryEntity.SortField, purchasePlanRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + purchasePlanRptQueryEntity.SortField + " " + purchasePlanRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetReceiptDetailRptInfo(List<string> sqlWhere, ReceiptDetailRptQueryEntity receiptDetailRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            StringBuilder sSQL = new StringBuilder();
            if (receiptDetailRptQueryEntity.SHOW_LPN)
            {
                sSQL.Append(" SELECT DISTINCT * ");
            }
            else
            {
                sSQL.Append(" SELECT RECEIPT_ID, RECEIPT_LINE_ID, PO_ID, OWNER_ID, EXTERN_RECEIPT_ID, RD_STATUS, STATUS_D, RECEIPT_TYPE_D, [STATUS], RECEIPT_TYPE, CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, RECEIPT_DATE))) AS RECEIPT_DATE, SKU_ID, SKU_DESCR, ");
                sSQL.Append(" EXPECTED_QTY AS EXPECTED_QTY, SUM(RECEIVED_QTY) AS RECEIVED_QTY, CONDITION_CODE, '' AS TO_LPN_ID, TO_LOT, VENDOR_ID, VENDOR_NAME, SKU_PROPERTY, RMA, ");
                sSQL.Append(" LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10, PRODUCE_DATE, [EXPIRY_DATE], EXTERNAL_LOT, ");
                sSQL.Append(" REMARK, SKU_CLASS_ID, SKU_CLASS_DESCR, SKU_GROUP, PACK_ID, '' AS SKU_UDF2, SKU_STYLE, UOM_DESCR, '' AS TRANS_ID, UNIT_PRICE, ");
                sSQL.Append(" SUM(PRICE) AS PRICE, SUM(TOTAL_GROSS_WGT) AS TOTAL_GROSS_WGT, SUM(TOTAL_CUBE) AS TOTAL_CUBE, SUM(TOTAL_WGT) AS TOTAL_WGT ");
            }
            sSQL.Append(" FROM ( ");
            sSQL.Append(" SELECT RD.RECEIPT_ID,RD.RECEIPT_LINE_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID AS EXTERN_RECEIPT_ID,RD.STATUS AS RD_STATUS,T.[TEXT] AS STATUS_D,T2.[TEXT] AS RECEIPT_TYPE_D,RD.STATUS,R.RECEIPT_TYPE,");
            sSQL.Append(" IT.TRANS_DATE AS RECEIPT_DATE,RD.SKU_ID,SKU.DESCR AS SKU_DESCR,RD.EXPECTED_QTY,IT.QTY AS RECEIVED_QTY,IT.HOLD_CODE AS CONDITION_CODE,IT.TO_LPN_ID,IT.LOT AS TO_LOT,IT.VENDOR_ID,V.COMPANY AS VENDOR_NAME,LAC.DESCR AS SKU_PROPERTY, R.RMA,");
            sSQL.Append(" IT.LOT_ATTR01,IT.LOT_ATTR02,IT.LOT_ATTR03,IT.LOT_ATTR04,IT.LOT_ATTR05,IT.LOT_ATTR06,IT.LOT_ATTR07,IT.LOT_ATTR08, LAC.DESCR AS LOT_ATTR09,IT.LOT_ATTR10,IT.PRODUCE_DATE,IT.EXPIRY_DATE,IT.EXTERNAL_LOT,");
            sSQL.Append(" RD.REMARK,SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,SKU.SKU_GROUP,SKU.PACK_ID,SKU.UDF2 AS SKU_UDF2,RD.UNIT_PRICE,ISNULL(IT.QTY * RD.UNIT_PRICE,0) AS PRICE,");
            sSQL.Append(" IT.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT,IT.QTY * SKU.[CUBE] AS TOTAL_CUBE,IT.QTY * SKU.NET_WGT AS TOTAL_WGT,SKU.SKU_STYLE,U.UOM_DESCR,IT.TRANS_ID   ");
            sSQL.Append(" FROM @_@RECEIPT_DETAIL RD  ");
            sSQL.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID   ");
            sSQL.Append(" LEFT JOIN @_@INV_TRANS IT ON RD.RECEIPT_ID = IT.RECEIPT_ID AND RD.RECEIPT_LINE_ID = IT.RECEIPT_LINE_ID ");
            sSQL.Append(" AND IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd'  AND IT.STATUS = 'OK' ");
            sSQL.Append(" LEFT JOIN @_@VENDOR V ON IT.VENDOR_ID = V.VENDOR_ID");
            sSQL.Append(" LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID   ");
            sSQL.Append(" LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID ");
            sSQL.Append(" LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1 ");
            sSQL.Append(" LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID");
            sSQL.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = RD.STATUS AND SCD.SYS_CODE_TYPE = 'ReceiptStatus' ");
            sSQL.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = R.RECEIPT_TYPE AND SCD2.SYS_CODE_TYPE = 'ReceiptType' ");
            sSQL.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            sSQL.Append(" LEFT JOIN sysadm.TRANSLATION T2 ON 'ReceiptType.'+R.RECEIPT_TYPE = T2.ITEM_ID AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE");
            sSQL.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON IT.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
            sSQL.Append(" INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            sSQL.Append(" WHERE R.IS_PALLETIZED = 'N' AND RD.STATUS IN ('InReceiving','ReceivedComplete','CLOSED') ");
            for (i = 0; i < sqlWhere.Count; i++)
            {
                sSQL.Append(" AND " + sqlWhere[i].ToString());
            }
            sSQL.Append(" UNION ALL ");
            sSQL.Append(" SELECT RD.RECEIPT_ID,RD.RECEIPT_LINE_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID AS EXTERN_RECEIPT_ID,RD.STATUS AS RD_STATUS,T.[TEXT] AS STATUS_D,T2.[TEXT] AS RECEIPT_TYPE_D,RD.STATUS,R.RECEIPT_TYPE,");
            sSQL.Append(" IT.TRANS_DATE AS RECEIPT_DATE,RD.SKU_ID,SKU.DESCR AS SKU_DESCR,RD.EXPECTED_QTY,IT.QTY AS RECEIVED_QTY,IT.HOLD_CODE AS CONDITION_CODE,IT.TO_LPN_ID,IT.LOT AS TO_LOT,IT.VENDOR_ID,V.COMPANY AS VENDOR_NAME,LAC.DESCR AS SKU_PROPERTY, R.RMA,");
            sSQL.Append(" IT.LOT_ATTR01,IT.LOT_ATTR02,IT.LOT_ATTR03,IT.LOT_ATTR04,IT.LOT_ATTR05,IT.LOT_ATTR06,IT.LOT_ATTR07,IT.LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,IT.LOT_ATTR10,IT.PRODUCE_DATE,IT.EXPIRY_DATE,IT.EXTERNAL_LOT,");
            sSQL.Append(" RD.REMARK,SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,SKU.SKU_GROUP,SKU.PACK_ID,SKU.UDF2 AS SKU_UDF2,RD.UNIT_PRICE,ISNULL(IT.QTY * RD.UNIT_PRICE,0) AS PRICE,");
            sSQL.Append(" IT.QTY * SKU.GROSS_WGT AS TOTAL_GROSS_WGT,IT.QTY * SKU.[CUBE] AS TOTAL_CUBE,IT.QTY * SKU.NET_WGT AS TOTAL_WGT,SKU.SKU_STYLE,U.UOM_DESCR ,IT.TRANS_ID   ");
            sSQL.Append(" FROM @_@RECEIPT_DETAIL_LPN RD  ");
            sSQL.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID   ");
            sSQL.Append(" LEFT JOIN @_@INV_TRANS IT ON RD.RECEIPT_ID = IT.RECEIPT_ID AND RD.RECEIPT_LINE_ID = IT.RECEIPT_LINE_ID ");
            sSQL.Append(" AND IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd'  AND IT.STATUS = 'OK' ");
            sSQL.Append(" LEFT JOIN @_@VENDOR V ON IT.VENDOR_ID = V.VENDOR_ID");
            sSQL.Append(" LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID   ");
            sSQL.Append(" LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID ");
            sSQL.Append(" LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1 ");
            sSQL.Append(" LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID");
            sSQL.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = RD.STATUS AND SCD.SYS_CODE_TYPE = 'ReceiptStatus' ");
            sSQL.Append(" LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = R.RECEIPT_TYPE AND SCD2.SYS_CODE_TYPE = 'ReceiptType' ");
            sSQL.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            sSQL.Append(" LEFT JOIN sysadm.TRANSLATION T2 ON 'ReceiptType.'+R.RECEIPT_TYPE = T2.ITEM_ID AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE");
            sSQL.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON IT.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
            sSQL.Append(" INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            sSQL.Append(" WHERE R.IS_PALLETIZED = 'Y' AND RD.STATUS IN ('InReceiving','ReceivedComplete','CLOSED') ");
            for (i = 0; i < sqlWhere.Count; i++)
            {
                sSQL.Append(" AND " + sqlWhere[i].ToString());
            }
            if (receiptDetailRptQueryEntity.SHOW_LPN)
            {
                sSQL.Append(" ) TEMP WHERE (VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID) OR ISNULL(VENDOR_ID,'') = '')");
            }
            else
            {
                sSQL.Append(" ) TEMP WHERE (VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID) OR ISNULL(VENDOR_ID,'') = '')");
                sSQL.Append(" GROUP BY RECEIPT_ID, RECEIPT_LINE_ID, PO_ID, OWNER_ID, EXTERN_RECEIPT_ID, RD_STATUS, STATUS_D, RECEIPT_TYPE_D, [STATUS], RECEIPT_TYPE, CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, RECEIPT_DATE))), SKU_ID, SKU_DESCR, ");
                sSQL.Append(" CONDITION_CODE, TO_LOT, VENDOR_ID, VENDOR_NAME, SKU_PROPERTY, RMA, ");
                sSQL.Append(" LOT_ATTR01, LOT_ATTR02, LOT_ATTR03, LOT_ATTR04, LOT_ATTR05, LOT_ATTR06, LOT_ATTR07, LOT_ATTR08, LOT_ATTR09, LOT_ATTR10, PRODUCE_DATE, [EXPIRY_DATE], EXTERNAL_LOT, ");
                sSQL.Append(" REMARK, SKU_CLASS_ID, SKU_CLASS_DESCR, SKU_GROUP, PACK_ID, SKU_STYLE, UOM_DESCR, UNIT_PRICE,EXPECTED_QTY ");
            }
            string sql = sSQL.ToString().Replace("@_@", whLoginID);
            if (!receiptDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, receiptDetailRptQueryEntity.CurrentPage, receiptDetailRptQueryEntity.PageSize, receiptDetailRptQueryEntity.SortField, receiptDetailRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + receiptDetailRptQueryEntity.SortField + " " + receiptDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetReceiptRptInfo(List<string> sqlWhere, ReceiptRptQueryEntity ReceiptRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT RECEIPT_ID,PO_ID,OWNER_ID,EXTERNAL_RECEIPT_ID,STATUS,RECEIPT_TYPE,VENDOR_ID,VENDOR_NAME,RECEIVED_DATE,RECEIPT_DATE,CREATED_DATE,REMARK,SKU_ID,SKU_DESCR,RMA,SKU_CLASS_ID,SKU_CLASS_DESCR,  SUM(EXPECTED_QTY) AS EXPECTED_QTY,SUM(RECEIVED_QTY) AS RECEIVED_QTY,SUM(DIFF_QTY) AS DIFF_QTY,SUM(TOTAL_GROSS_WGT) AS TOTAL_GROSS_WGT,SUM(TOTAL_CUBE) AS TOTAL_CUBE,SUM(TOTAL_WGT) AS TOTAL_WGT,PACK_ID,UOM_DESCR  FROM (  SELECT RD.RECEIPT_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID,T.[TEXT] AS STATUS,T2.[TEXT] AS RECEIPT_TYPE,RD.VENDOR_ID,RD.VENDOR_NAME,RD.RECEIVED_DATE,RD.RECEIPT_DATE,RD.CREATED_DATE,R.REMARK,RD.SKU_ID,SKU.DESCR AS SKU_DESCR,RD.EXPECTED_QTY,RD.RECEIVED_QTY,(RD.EXPECTED_QTY*SKU.GROSS_WGT) AS TOTAL_GROSS_WGT,(RD.EXPECTED_QTY*SKU.[CUBE]) AS TOTAL_CUBE,RD.RMA,SKU.SKU_CLASS_ID,(RD.EXPECTED_QTY - RD.RECEIVED_QTY) AS DIFF_QTY,(RD.EXPECTED_QTY*SKU.NET_WGT) AS TOTAL_WGT,SC.DESCR AS SKU_CLASS_DESCR,SKU.PACK_ID,U.UOM_DESCR  FROM @_@RECEIPT_DETAIL RD LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID   LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID    LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID  LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1  LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SC.OWNER_ID = SKU.OWNER_ID  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = RD.STATUS AND SCD.SYS_CODE_TYPE = 'ReceiptStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = R.RECEIPT_TYPE AND SCD2.SYS_CODE_TYPE = 'ReceiptType' LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION T2 ON 'ReceiptType.'+R.RECEIPT_TYPE = T2.ITEM_ID AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE  LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON RD.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE R.IS_PALLETIZED = 'N'  UNION ALL  SELECT RD.RECEIPT_ID,RD.PO_ID,RD.OWNER_ID,R.EXTERNAL_RECEIPT_ID,T.[TEXT] AS STATUS,T2.[TEXT] AS RECEIPT_TYPE,RD.VENDOR_ID,RD.VENDOR_NAME,RD.RECEIVED_DATE,RD.RECEIPT_DATE,RD.CREATED_DATE,R.REMARK,RD.SKU_ID,SKU.DESCR AS SKU_DESCR,RD.EXPECTED_QTY,RD.RECEIVED_QTY,(RD.EXPECTED_QTY*SKU.GROSS_WGT) AS TOTAL_GROSS_WGT,(RD.EXPECTED_QTY*SKU.[CUBE]) AS TOTAL_CUBE,RD.RMA,SKU.SKU_CLASS_ID,(RD.EXPECTED_QTY - RD.RECEIVED_QTY) AS DIFF_QTY,(RD.EXPECTED_QTY*SKU.NET_WGT) AS TOTAL_WGT,SC.DESCR AS SKU_CLASS_DESCR,SKU.PACK_ID,U.UOM_DESCR  FROM @_@RECEIPT_DETAIL_LPN RD LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = RD.RECEIPT_ID   LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = RD.OWNER_ID AND SKU.SKU_ID = RD.SKU_ID LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID  LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1  LEFT JOIN @_@SKU_CLASS SC ON SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SC.OWNER_ID = SKU.OWNER_ID  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = RD.STATUS AND SCD.SYS_CODE_TYPE = 'ReceiptStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = R.RECEIPT_TYPE AND SCD2.SYS_CODE_TYPE = 'ReceiptType' LEFT JOIN sysadm.TRANSLATION T ON 'ReceiptStatus.'+RD.STATUS = T.ITEM_ID           AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'ReceiptType.'+R.RECEIPT_TYPE = T2.ITEM_ID           AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON RD.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' INNER JOIN SYSADM.USER_OWNER UO ON R.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID    WHERE R.IS_PALLETIZED = 'Y'  ) TEMP WHERE (VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE [USER_ID] = @USER_ID) OR VENDOR_ID IS NULL OR VENDOR_ID = '') ";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            sql = sql + " GROUP BY RECEIPT_ID,PO_ID,OWNER_ID,EXTERNAL_RECEIPT_ID,STATUS,RECEIPT_TYPE,VENDOR_ID,VENDOR_NAME,RECEIVED_DATE,RECEIPT_DATE,CREATED_DATE,REMARK,SKU_ID,SKU_DESCR,RMA,SKU_CLASS_ID,SKU_CLASS_DESCR,PACK_ID,UOM_DESCR";
            if (!ReceiptRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, ReceiptRptQuery.CurrentPage, ReceiptRptQuery.PageSize, ReceiptRptQuery.SortField, ReceiptRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + ReceiptRptQuery.SortField + " " + ReceiptRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetRentWhDetailRptDataSet(List<string> sqlWhere, RentWhDetailRptQueryEntity rentWhDetailRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT O.OWNER_ID,O.COMPANY AS OWNER_D, RHD.ZONE_NO,RHD.LOCATION, ");
            strSql.Append(" C.MANAGE_TYPE,T.TEXT AS MANAGE_TYPE_D,RHD.AREA,RHD.UNIT_PRICE,ISNULL(RHD.TOTAL_PRICE,0) AS TOTAL_PRICE, ");
            strSql.Append(" RHD.MANAGE_AMOUNT,ISNULL(RHD.TOTAL_PRICE,0)+RHD.MANAGE_AMOUNT AS TOTAL_AMOUNT, ");
            strSql.Append(" CONVERT(VARCHAR(20),C.END_TIME,23) AS END_TIME,D.DEPARTMENT_ID,D.DESCR AS DEPARTMENT_D ");
            strSql.Append(" FROM @_@RENT_WH_DETAIL RHD ");
            strSql.Append(" LEFT JOIN @_@CONTRACT C ON C.CONTRACT_ID = RHD.CONTRACT_ID ");
            strSql.Append(" LEFT JOIN @_@OWNER O ON O.OWNER_ID = C.OWNER_ID ");
            strSql.Append(" LEFT JOIN @_@DEPARTMENT D ON D.DEPARTMENT_ID = C.DEPARTMENT_ID ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'MANAGETYPE.'+C.MANAGE_TYPE = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ");
            strSql.Append(" WHERE C.IS_ACTIVE = 'Y' AND C.IS_AUDIT = 'Y' ");
            strSql.AppendFormat(" {0}  ", strWhere);
            strSql = strSql.Replace("@_@", whLoginID);
            if (!rentWhDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), rentWhDetailRptQueryEntity.CurrentPage, rentWhDetailRptQueryEntity.PageSize, rentWhDetailRptQueryEntity.SortField, rentWhDetailRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + rentWhDetailRptQueryEntity.SortField + " " + rentWhDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetSafeInventoryRptInfo(List<string> sqlWhere, SafeInventoryRptQueryEntity safeInventoryRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = ("SELECT DISTINCT A.OWNER_ID AS OWNER_ID, A.SKU_ID AS SKU_ID,A.SKU_CLASS_ID AS SKU_CLASS_ID, A.DESCR AS DESCR, A.DESCR2 AS DESCR2, ISNULL(A.MIN_QTY,0) AS MIN_QTY, ISNULL(A.MAX_QTY,0) AS MAX_QTY," + (safeInventoryRptQuery.SHOW_VENDOR ? "LA.VENDOR_ID, " : " '' AS VENDOR_ID,") + " ISNULL(A.REORDER_POINT,0) AS REORDER_POINT, SUM(ISNULL(B.QTY,0)) AS QTY, SUM(ISNULL(B.PREALLOCATED_QTY,0)) AS PREALLOCATED_QTY, SUM((ISNULL(B.QTY,0) - ISNULL(B.PREALLOCATED_QTY,0))) AS AVAILABLE_QTY,A.PACK_ID,U.UOM_DESCR, MAX(LA.RECEIPT_DATE) AS LAST_RECEIPT_DATE,DATEDIFF(DAY, MAX(LA.RECEIPT_DATE), GETDATE()) AS LAST_DAYS,  SUM(CASE WHEN DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) < 30 THEN ISNULL(B.QTY,0) END) AS DAYS_1,  SUM(CASE WHEN DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) >= 30 AND DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) < 60 THEN ISNULL(B.QTY,0) END) AS DAYS_30,  SUM(CASE WHEN DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) >= 60 AND DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) < 90 THEN ISNULL(B.QTY,0) END) AS DAYS_60,  SUM(CASE WHEN DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) >= 90 AND DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) < 120 THEN ISNULL(B.QTY,0) END) AS DAYS_90,  SUM(CASE WHEN DATEDIFF(DAY, LA.RECEIPT_DATE, GETDATE()) >= 120 THEN ISNULL(B.QTY,0) END) AS DAYS_120  FROM @_@SKU AS A  LEFT JOIN  @_@PACK PACK ON A.PACK_ID = PACK.PACK_ID  LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1  LEFT JOIN  @_@INV_LOT  AS B  ON A.SKU_ID=B.SKU_ID AND A.OWNER_ID = B.OWNER_ID  LEFT JOIN  @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = A.OWNER_ID AND LA.SKU_ID = A.SKU_ID AND LA.LOT = B.LOT  INNER JOIN SYSADM.USER_OWNER UO ON A.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE (ISNULL(A.MIN_QTY,0) > 0 OR ISNULL(A.MAX_QTY,0) > 0)  AND A.IS_ACTIVE='Y' ").ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (safeInventoryRptQuery.SHOW_ALL)
            {
                sql = sql + " AND B.QTY > 0 ";
            }
            sql = sql + " GROUP BY A.OWNER_ID, A.SKU_ID,A.SKU_CLASS_ID, A.DESCR, A.DESCR2, A.MIN_QTY, A.MAX_QTY, A.REORDER_POINT,A.PACK_ID,U.UOM_DESCR " + (safeInventoryRptQuery.SHOW_VENDOR ? ",LA.VENDOR_ID " : "");
            if (!safeInventoryRptQuery.SHOW_ALL)
            {
                sql = sql + " HAVING (ISNULL(A.MIN_QTY,0) > 0 AND SUM(ISNULL(B.QTY,0) - ISNULL(B.PREALLOCATED_QTY,0)) < ISNULL(A.MIN_QTY,0)) OR (ISNULL(A.MAX_QTY,0) > 0 AND SUM(ISNULL(B.QTY,0) - ISNULL(B.PREALLOCATED_QTY,0)) > ISNULL(A.MAX_QTY,0))";
            }
            if (!safeInventoryRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, safeInventoryRptQuery.CurrentPage, safeInventoryRptQuery.PageSize, safeInventoryRptQuery.SortField, safeInventoryRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + safeInventoryRptQuery.SortField + " " + safeInventoryRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShelflifeRptInfo(List<string> sqlWhere, ShelflifeRptQueryEntity ShelflifeRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT DISTINCT * FROM ( ");
            sb.Append(" SELECT DISTINCT ISL.OWNER_ID, ISL.SKU_ID, SKU.DESCR AS SKU_DESCR,SKU.DESCR2 AS SKU_DESCR2,SKU.PACK_ID AS PACK_ID ,SKU.SKU_CLASS_ID,SC.DESCR AS SKU_CLASS_DESCR,SKU.SKU_GROUP,SKU.UDF2 AS SKU_UDF2,");
            sb.Append(" IL.LOT,IL.QTY,IL.UNIT_PRICE,IL.QTY * IL.UNIT_PRICE AS PRICE,U.UOM_DESCR,");
            sb.Append(" CASE WHEN DATEDIFF(D, GETDATE(), LA.EXPIRY_DATE) > 0 THEN '未过期' ELSE '已过期' END AS IS_EXPIRY, ");
            sb.Append(" DATEDIFF(D, GETDATE(), LA.EXPIRY_DATE) AS EXPIRY_DAY_COUNT, ");
            sb.Append(" DATEDIFF(D, LA.PRODUCE_DATE, LA.EXPIRY_DATE) AS SHELF_LIFE, ");
            sb.Append(" LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LAC.DESCR AS LOT_ATTR09, LA.LOT_ATTR10, ");
            sb.Append(" LA.PRODUCE_DATE, LA.EXPIRY_DATE AS Expiry_Date, LA.VENDOR_ID, LA.EXTERNAL_LOT  ");
            sb.Append(" FROM @_@INV_SKU_LOC AS ISL ");
            sb.Append(" LEFT JOIN @_@INV_LOT AS IL ON ISL.OWNER_ID = IL.OWNER_ID AND ISL.SKU_ID = IL.SKU_ID ");
            sb.Append(" LEFT JOIN @_@SKU AS SKU ON ISL.OWNER_ID = SKU.OWNER_ID AND ISL.SKU_ID = SKU.SKU_ID ");
            sb.Append(" LEFT JOIN  @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID ");
            sb.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
            sb.Append(" LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = SKU.OWNER_ID AND SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID ");
            sb.Append(" LEFT JOIN @_@LOT_ATTRIBUTE AS LA ON IL.LOT = LA.LOT ");
            sb.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            sb.Append(" WHERE (LA.EXPIRY_DATE IS NOT NULL) AND (LA.EXPIRY_DATE <> '') ");
            sb.Append(" ) TEMP INNER JOIN SYSADM.USER_OWNER UO ON TEMP.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID");
            string sql = sb.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!ShelflifeRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, ShelflifeRptQuery.CurrentPage, ShelflifeRptQuery.PageSize, ShelflifeRptQuery.SortField, ShelflifeRptQuery.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + ShelflifeRptQuery.SortField + " " + ShelflifeRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentOrderDetailRptInfo(List<string> sqlWhere, ShipmentOrderDetailRptQueryEntity shipmentOrderDetailRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT * FROM (  SELECT OD.ORDER_ID,OD.LINE_ID, O.EXTERN_ORDER_ID, O.REFERENCE_NUM, OD.OWNER_ID, PD.STATUS AS OD_STATUS,T.[TEXT] AS STATUS,   O.ORDER_DATE,O.TYPE AS ORDER_TYPE, T2.[TEXT] AS TYPE, O.REQUESTED_SHIP_DATE, OD.ACTUAL_SHIP_DATE, SKU.SKU_ID,   OD.UOM_ID, SKU.SKU_CLASS_ID, SKU.DESCR, OD.ORIGINAL_QTY, SUM(PD.QTY) AS SHIPPED_QTY,   OD.ORIGINAL_QTY - OD.SHIPPED_QTY AS OPEN_QTY, OD.PREALLOCATED_QTY, OD.ALLOCATED_QTY, OD.PICKED_QTY, OD.ORIGINAL_QTY * SKU.GROSS_WGT AS TotalWeight,   OD.ORIGINAL_QTY * SKU.[CUBE] AS TotalCube, O.CONSIGNEE_ID, O.C_ADDRESS,   O.C_COMPANY, LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03,   LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07,   LA.LOT_ATTR08, LAC.DESCR AS LOT_ATTR09, LA.LOT_ATTR10,PD.LOT,  LA.PRODUCE_DATE, LA.EXPIRY_DATE, LA.EXTERNAL_LOT,LA.RECEIPT_DATE, LA.VENDOR_ID, OD.REMARK,V.COMPANY,SC.DESCR AS SKU_CLASS_DESCR, LAC.DESCR  AS SKU_PROPERTY,OD.ORIGINAL_QTY * SKU.NET_WGT AS TOTAL_WGT,   OD.CREATED_BY, OD.CREATED_DATE,IL.UNIT_PRICE,SKU.SKU_STYLE,SKU.SKU_GROUP,U.UOM_DESCR,SKU.PACK_ID,WD.WAVE_ID   FROM  @_@ORDER_DETAIL OD  LEFT JOIN  @_@WAVE_DETAIL WD ON WD.ORDER_ID= OD.ORDER_ID   LEFT JOIN @_@PICK_DETAIL PD ON OD.ORDER_ID=PD.ORDER_ID AND OD.LINE_ID = PD.ORDER_LINE_ID  LEFT JOIN  @_@LOT_ATTRIBUTE LA ON PD.LOT =LA.LOT  LEFT  JOIN  @_@ORDERS O ON OD.ORDER_ID = O.ORDER_ID    LEFT JOIN @_@SKU SKU ON OD.OWNER_ID = SKU.OWNER_ID AND OD.SKU_ID = SKU.SKU_ID LEFT JOIN  @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID  LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1  LEFT JOIN @_@SKU_CLASS SC ON  SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SC.OWNER_ID = SKU.OWNER_ID LEFT JOIN @_@VENDOR V ON  OD.VENDOR_ID = V.VENDOR_ID  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = OD.STATUS AND SCD.SYS_CODE_TYPE = 'OrderStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = O.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType' LEFT JOIN sysadm.TRANSLATION T ON 'OrderStatus.'+OD.STATUS = T.ITEM_ID           AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+O.TYPE = T2.ITEM_ID           AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'  LEFT JOIN @_@INV_LOT IL ON PD.LOT = IL.LOT  GROUP BY OD.ORDER_ID,OD.LINE_ID, O.EXTERN_ORDER_ID, O.REFERENCE_NUM,O.TYPE,OD.OWNER_ID, PD.STATUS ,T.[TEXT], O.ORDER_DATE, T2.[TEXT], O.REQUESTED_SHIP_DATE, OD.ACTUAL_SHIP_DATE, SKU.SKU_ID,  OD.UOM_ID, SKU.SKU_CLASS_ID, SKU.DESCR, OD.ORIGINAL_QTY, OD.ORIGINAL_QTY - OD.SHIPPED_QTY , OD.PREALLOCATED_QTY, OD.ALLOCATED_QTY, OD.PICKED_QTY, OD.ORIGINAL_QTY * SKU.[CUBE], O.CONSIGNEE_ID, O.C_ADDRESS, O.C_COMPANY, LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03,   LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07,  LA.LOT_ATTR08, LAC.DESCR , LA.LOT_ATTR10,PD.LOT,LA.PRODUCE_DATE, LA.EXPIRY_DATE, LA.EXTERNAL_LOT,LA.RECEIPT_DATE, LA.VENDOR_ID, OD.REMARK,V.COMPANY,SC.DESCR , LAC.DESCR  ,  OD.CREATED_BY, OD.CREATED_DATE ,SKU.GROSS_WGT,SKU.NET_WGT,IL.UNIT_PRICE,SKU.SKU_STYLE,SKU.SKU_GROUP,U.UOM_DESCR,SKU.PACK_ID,WD.WAVE_ID  ) TEMP WHERE (CONSIGNEE_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR CONSIGNEE_ID IS NULL OR CONSIGNEE_ID = '' OR CONSIGNEE_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID)) AND (VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE USER_ID = @USER_ID) OR VENDOR_ID = '' OR VENDOR_ID IS NULL)";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!shipmentOrderDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentOrderDetailRptQueryEntity.CurrentPage, shipmentOrderDetailRptQueryEntity.PageSize, shipmentOrderDetailRptQueryEntity.SortField, shipmentOrderDetailRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + shipmentOrderDetailRptQueryEntity.SortField + " " + shipmentOrderDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentOrderRptInfo(List<string> sqlWhere, ShipmentOrderRptQueryEntity shipmentOrderRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT OD.ORDER_ID AS ORDER_ID,OD.LINE_ID AS LINE_ID ,O.EXTERNAL_ORDER_ID2 AS EXTERNAL_ORDER_ID2 ,O.REFERENCE_NUM AS REFERENCE_NUM, O.EXTERN_ORDER_ID AS EXTERN_ORDER_ID, OD.OWNER_ID AS OWNER_ID, T.[TEXT] AS STATUS,   O.ORDER_DATE AS ORDER_DATE , T2.[TEXT] AS TYPE, O.REQUESTED_SHIP_DATE AS REQUESTED_SHIP_DATE , O.ACTUAL_SHIP_DATE AS ACTUAL_SHIP_DATE, SKU.SKU_ID AS SKU_ID,   OD.UOM_ID AS UOM_ID , SKU.SKU_CLASS_ID AS SKU_CLASS_ID , SKU.DESCR AS DESCR, OD.ORIGINAL_QTY AS ORIGINAL_QTY, SUM(PD.QTY) AS SHIPPED_QTY, O.CARRIER_ID AS CARRIER_ID,O.CARRIER_NAME AS CARRIER_NAME,  OD.ORIGINAL_QTY - OD.SHIPPED_QTY AS OPEN_QTY, OD.PREALLOCATED_QTY AS PREALLOCATED_QTY, OD.ALLOCATED_QTY AS ALLOCATED_QTY, OD.PICKED_QTY AS PICKED_QTY, OD.ORIGINAL_QTY * SKU.GROSS_WGT AS TotalWeight,   OD.ORIGINAL_QTY * SKU.[CUBE] AS TotalCube, O.CONSIGNEE_ID AS CONSIGNEE_ID, O.C_ADDRESS AS C_ADDRESS,   O.C_COMPANY AS C_COMPANY ,LA.LOT_ATTR01 AS LOT_ATTR01, LA.LOT_ATTR02 AS LOT_ATTR02, LA.LOT_ATTR03 AS LOT_ATTR03,   LA.LOT_ATTR04 AS LOT_ATTR04, LA.LOT_ATTR05 AS LOT_ATTR05, LA.LOT_ATTR06 AS LOT_ATTR06, LA.LOT_ATTR07 AS LOT_ATTR07,   LA.LOT_ATTR08 AS LOT_ATTR08, LAC.DESCR AS LOT_ATTR09, LA.LOT_ATTR10 AS LOT_ATTR10, LA.PRODUCE_DATE AS PRODUCE_DATE,   LA.EXPIRY_DATE AS EXPIRY_DATE, LA.EXTERNAL_LOT AS EXTERNAL_LOT, LA.VENDOR_ID AS VENDOR_ID, OD.REMARK AS REMARK,V.COMPANY AS COMPANY,SC.DESCR AS SKU_CLASS_DESCR, LAC.DESCR AS SKU_PROPERTY,OD.ORIGINAL_QTY * SKU.NET_WGT AS TOTAL_WGT,   OD.CREATED_BY AS CREATED_BY, OD.CREATED_DATE AS CREATED_DATE,SKU.PACK_ID,U.UOM_DESCR   FROM  @_@ORDER_DETAIL OD    LEFT JOIN  @_@PICK_DETAIL PD ON OD.ORDER_ID=PD.ORDER_ID AND OD.LINE_ID = PD.ORDER_LINE_ID  LEFT JOIN  @_@LOT_ATTRIBUTE LA ON PD.LOT =LA.LOT  LEFT JOIN  @_@ORDERS O ON OD.ORDER_ID = O.ORDER_ID   LEFT JOIN  @_@SKU SKU ON OD.OWNER_ID = SKU.OWNER_ID AND OD.SKU_ID = SKU.SKU_ID  LEFT JOIN  @_@PACK P ON P.PACK_ID = SKU.PACK_ID  LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1  LEFT JOIN @_@SKU_CLASS SC ON  SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID  LEFT JOIN @_@VENDOR V ON  OD.VENDOR_ID = V.VENDOR_ID  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = OD.STATUS AND SCD.SYS_CODE_TYPE = 'OrderStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = O.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType' LEFT JOIN sysadm.TRANSLATION T ON 'OrderStatus.'+OD.STATUS = T.ITEM_ID           AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+O.TYPE = T2.ITEM_ID           AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' WHERE O.STATUS = 'SHIPPED' AND (O.CONSIGNEE_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR O.CONSIGNEE_ID IS NULL OR O.CONSIGNEE_ID = '' OR O.CONSIGNEE_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID))";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            sql = sql + " GROUP BY OD.ORDER_ID,OD.LINE_ID,O.EXTERNAL_ORDER_ID2,O.REFERENCE_NUM , O.EXTERN_ORDER_ID , OD.OWNER_ID , T.[TEXT],  O.ORDER_DATE , T2.[TEXT], O.REQUESTED_SHIP_DATE , O.ACTUAL_SHIP_DATE, SKU.SKU_ID , OD.UOM_ID , SKU.SKU_CLASS_ID , SKU.DESCR , OD.ORIGINAL_QTY , O.CARRIER_ID ,O.CARRIER_NAME , OD.ORIGINAL_QTY , OD.SHIPPED_QTY , OD.PREALLOCATED_QTY , OD.ALLOCATED_QTY , OD.PICKED_QTY , OD.ORIGINAL_QTY , SKU.GROSS_WGT ,  OD.ORIGINAL_QTY , SKU.[CUBE] , O.CONSIGNEE_ID , O.C_ADDRESS , O.C_COMPANY ,LA.LOT_ATTR01, LA.LOT_ATTR02 , LA.LOT_ATTR03 ,   LA.LOT_ATTR04 , LA.LOT_ATTR05, LA.LOT_ATTR06 , LA.LOT_ATTR07 ,   LA.LOT_ATTR08 , LAC.DESCR , LA.LOT_ATTR10 , LA.PRODUCE_DATE , LA.EXPIRY_DATE , LA.EXTERNAL_LOT , LA.VENDOR_ID , OD.REMARK ,V.COMPANY ,SC.DESCR , LAC.DESCR,OD.ORIGINAL_QTY, SKU.NET_WGT, OD.CREATED_BY , OD.CREATED_DATE,SKU.PACK_ID,U.UOM_DESCR ";
            if (!shipmentOrderRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentOrderRptQuery.CurrentPage, shipmentOrderRptQuery.PageSize, shipmentOrderRptQuery.SortField, shipmentOrderRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + shipmentOrderRptQuery.SortField + " " + shipmentOrderRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentOrderRptStatistics(List<string> sqlWhere, ShipmentOrderRptQueryEntity shipmentOrderRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT OD.ORDER_ID AS ORDER_ID,OD.LINE_ID AS LINE_ID ,O.EXTERNAL_ORDER_ID2 AS EXTERNAL_ORDER_ID2 ,O.REFERENCE_NUM AS REFERENCE_NUM, O.EXTERN_ORDER_ID AS EXTERN_ORDER_ID, OD.OWNER_ID AS OWNER_ID, T.[TEXT] AS STATUS,   O.ORDER_DATE AS ORDER_DATE , T2.[TEXT] AS TYPE, O.REQUESTED_SHIP_DATE AS REQUESTED_SHIP_DATE , O.ACTUAL_SHIP_DATE AS ACTUAL_SHIP_DATE, SKU.SKU_ID AS SKU_ID,   OD.UOM_ID AS UOM_ID , SKU.SKU_CLASS_ID AS SKU_CLASS_ID , SKU.DESCR AS DESCR, OD.ORIGINAL_QTY AS ORIGINAL_QTY, OD.SHIPPED_QTY AS SHIPPED_QTY, O.CARRIER_ID AS CARRIER_ID,O.CARRIER_NAME AS CARRIER_NAME,  OD.ORIGINAL_QTY - OD.SHIPPED_QTY AS OPEN_QTY, OD.PREALLOCATED_QTY AS PREALLOCATED_QTY, OD.ALLOCATED_QTY AS ALLOCATED_QTY, OD.PICKED_QTY AS PICKED_QTY, OD.ORIGINAL_QTY * SKU.GROSS_WGT AS TotalWeight,   OD.ORIGINAL_QTY * SKU.[CUBE] AS TotalCube, O.CONSIGNEE_ID AS CONSIGNEE_ID, O.C_ADDRESS AS C_ADDRESS,   O.C_COMPANY AS C_COMPANY,OD.REMARK AS REMARK,V.COMPANY AS COMPANY,SC.DESCR AS SKU_CLASS_DESCR,OD.ORIGINAL_QTY * SKU.NET_WGT AS TOTAL_WGT,  OD.CREATED_BY AS CREATED_BY, OD.CREATED_DATE AS CREATED_DATE   FROM  @_@ORDER_DETAIL OD    LEFT  JOIN @_@ORDERS O ON OD.ORDER_ID = O.ORDER_ID LEFT JOIN   @_@SKU SKU ON OD.OWNER_ID = SKU.OWNER_ID AND OD.SKU_ID = SKU.SKU_ID LEFT JOIN @_@SKU_CLASS SC ON  SKU.SKU_CLASS_ID = SC.SKU_CLASS_ID AND SKU.OWNER_ID = SC.OWNER_ID  LEFT JOIN @_@VENDOR V ON  OD.VENDOR_ID = V.VENDOR_ID  LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = OD.STATUS AND SCD.SYS_CODE_TYPE = 'OrderStatus' LEFT JOIN @_@SYS_CODE_DETAIL SCD2 ON SCD2.SYS_CODE = O.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType' LEFT JOIN sysadm.TRANSLATION T ON 'OrderStatus.'+OD.STATUS = T.ITEM_ID           AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+O.TYPE = T2.ITEM_ID           AND  T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG+'-'+T2.COUNTRY = @LANGUAGE INNER JOIN SYSADM.USER_OWNER UO ON OD.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID  WHERE O.STATUS IN ('PartShipped','Shipped') AND (O.CONSIGNEE_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR O.CONSIGNEE_ID IS NULL OR O.CONSIGNEE_ID = '' OR O.CONSIGNEE_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID))";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!shipmentOrderRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentOrderRptQuery.CurrentPage, shipmentOrderRptQuery.PageSize, shipmentOrderRptQuery.SortField, shipmentOrderRptQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + shipmentOrderRptQuery.SortField + " " + shipmentOrderRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentOrderStatusRptInfo(List<string> sqlWhere, ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT T.TEXT AS STATUS, Os.ORDER_ID, Os.EXTERN_ORDER_ID, Os.REFERENCE_NUM, Os.OWNER_ID, T2.TEXT AS TYPE, Os.CONSIGNEE_ID, Os.C_COMPANY, Os.C_ADDRESS,  Os.ORDER_DATE, Os.REQUESTED_SHIP_DATE, Os.ACTUAL_SHIP_DATE, Os.REMARK,Os.CARRIER_ID,Os.CARRIER_NAME,Os.TYPE AS O_TYPE,Os.STATUS AS O_STATUS  FROM @_@ORDERS AS Os LEFT JOIN @_@CUSTOMER ON Os.CONSIGNEE_ID = @_@CUSTOMER.CUSTOMER_ID  LEFT JOIN @_@OWNER ON Os.OWNER_ID = @_@OWNER.OWNER_ID  LEFT JOIN @_@SYS_CODE_DETAIL AS SCD ON SCD.SYS_CODE = Os.STATUS AND SCD.SYS_CODE_TYPE = 'OrderStatus'  LEFT JOIN @_@SYS_CODE_DETAIL AS SCD2 ON SCD2.SYS_CODE = Os.TYPE AND SCD2.SYS_CODE_TYPE = 'OrderType'  LEFT JOIN sysadm.TRANSLATION AS T ON 'OrderStatus.' + Os.STATUS = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG + '-' + T.COUNTRY = @LANGUAGE  LEFT JOIN sysadm.TRANSLATION AS T2 ON 'OrderType.' + Os.TYPE = T2.ITEM_ID AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG + '-' + T2.COUNTRY = @LANGUAGE  INNER JOIN sysadm.USER_OWNER AS UO ON Os.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID  WHERE (Os.CONSIGNEE_ID IN (SELECT CUSTOMER_ID FROM SYSADM.USER_CUSTOMER WHERE [USER_ID] = @USER_ID) OR Os.CONSIGNEE_ID IS NULL OR Os.CONSIGNEE_ID = '' OR Os.CONSIGNEE_ID IN (SELECT WH_DB_NAME FROM SYSADM.USER_WH UW INNER JOIN SYSADM.db_config DC ON UW.WH_DB_ID = DC.WH_DB_ID WHERE [USER_ID] = @USER_ID)) ";
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            if (!shipmentOrderStatusRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentOrderStatusRptQueryEntity.CurrentPage, shipmentOrderStatusRptQueryEntity.PageSize, shipmentOrderStatusRptQueryEntity.SortField, shipmentOrderStatusRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + shipmentOrderStatusRptQueryEntity.SortField + " " + shipmentOrderStatusRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentStatByCustomerRptDataSet(List<string> sqlWhere, ShipmentStatByCustomerRptQueryEntity shipmentStatByCustomerRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT O.CONSIGNEE_ID AS CUSTOMER_ID, O.C_COMPANY AS CUSTOMER_NAME, ");
            strSql.Append(" COUNT(DISTINCT O.ORDER_ID) AS ORDERS_COUNT,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0)) QTY,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(S.GROSS_WGT,0)) AS GROSS_WGT,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(S.[CUBE],0)) AS [CUBE],");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(IL.UNIT_PRICE,0)) AS PRICE");
            strSql.Append(" FROM @_@ORDERS O LEFT JOIN @_@PICK_DETAIL PD ON PD.ORDER_ID = O.ORDER_ID AND PD.[STATUS] = 'Shipped'");
            strSql.Append("   LEFT JOIN @_@SKU S ON S.OWNER_ID = PD.OWNER_ID AND S.SKU_ID = PD.SKU_ID");
            strSql.Append("   LEFT JOIN @_@INV_LOT IL ON IL.OWNER_ID = PD.OWNER_ID AND IL.SKU_ID = PD.SKU_ID AND IL.LOT = PD.LOT");
            strSql.Append("   INNER JOIN sysadm.USER_OWNER UO ON O.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append(" WHERE O.[STATUS] IN ('Shipped','PartShipped') ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" AND EXISTS(SELECT 1 FROM @_@ORDER_DETAIL WHERE ORDER_ID = O.ORDER_ID) ");
            strSql.Append(" GROUP BY O.CONSIGNEE_ID, O.C_COMPANY");
            string sql = string.Empty;
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'").Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            if (!shipmentStatByCustomerRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentStatByCustomerRptQueryEntity.CurrentPage, shipmentStatByCustomerRptQueryEntity.PageSize, shipmentStatByCustomerRptQueryEntity.SortField, shipmentStatByCustomerRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + shipmentStatByCustomerRptQueryEntity.SortField + " " + shipmentStatByCustomerRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentStatByOrderRptDataSet(List<string> sqlWhere, ShipmentStatByOrderRptQueryEntity shipmentStatByOrderRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT A.ORDER_ID, A.ORDER_STATUS, A.ORDER_TYPE, A.REFERENCE_NUM, A.EXTERN_ORDER_ID, A.CUSTOMER_ID,A.CUSTOMER_NAME, A.CUSTOMER_ADDRESS,");
            strSql.Append(" A.CARRIER_ID,A.CARRIER_NAME,A.CREATED_DATE,A.ORDER_DATE,A.DELIVERY_DATE,A.REQUESTED_SHIP_DATE,A.ACTUAL_SHIP_DATE,A.REMARK,");
            strSql.Append(" A.QTY,A.GROSS_WGT,A.[CUBE],A.PRICE,SUM(OD.ORIGINAL_QTY) AS ORIGINAL_QTY ");
            strSql.Append(" FROM (");
            strSql.Append(" SELECT O.ORDER_ID, T.[TEXT] AS ORDER_STATUS, T2.[TEXT] AS ORDER_TYPE, O.REFERENCE_NUM, O.EXTERN_ORDER_ID,");
            strSql.Append(" O.CONSIGNEE_ID AS CUSTOMER_ID, O.C_COMPANY AS CUSTOMER_NAME, O.C_ADDRESS AS CUSTOMER_ADDRESS,");
            strSql.Append(" O.CARRIER_ID, O.CARRIER_NAME, O.CREATED_DATE, O.ORDER_DATE, O.DELIVERY_DATE, O.REQUESTED_SHIP_DATE, O.ACTUAL_SHIP_DATE, O.REMARK,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0)) QTY,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(S.GROSS_WGT,0)) AS GROSS_WGT,");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(S.[CUBE],0)) AS [CUBE],");
            strSql.Append(" SUM(ISNULL(PD.QTY, 0) * ISNULL(IL.UNIT_PRICE,0)) AS PRICE");
            strSql.Append(" FROM @_@ORDERS O INNER JOIN @_@PICK_DETAIL PD ON PD.ORDER_ID = O.ORDER_ID AND PD.[STATUS] = 'Shipped'");
            strSql.Append("   LEFT JOIN @_@SKU S ON S.OWNER_ID = PD.OWNER_ID AND S.SKU_ID = PD.SKU_ID");
            strSql.Append("   LEFT JOIN @_@INV_LOT IL ON IL.OWNER_ID = PD.OWNER_ID AND IL.SKU_ID = PD.SKU_ID AND IL.LOT = PD.LOT");
            strSql.Append("   LEFT JOIN sysadm.TRANSLATION T ON 'OrderStatus.' + O.[STATUS] = T.ITEM_ID AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG + '-' + T.COUNTRY = @LANGUAGE");
            strSql.Append("   LEFT JOIN sysadm.TRANSLATION T2 ON 'OrderType.'+ O.TYPE = T2.ITEM_ID AND T2.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T2.LANG + '-' + T2.COUNTRY = @LANGUAGE");
            strSql.Append("   INNER JOIN sysadm.USER_OWNER UO ON O.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID ");
            strSql.Append(" WHERE O.[STATUS] IN ('Shipped','PartShipped') ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" GROUP BY O.ORDER_ID, T.[TEXT], T2.[TEXT], O.REFERENCE_NUM, O.EXTERN_ORDER_ID,");
            strSql.Append(" O.CONSIGNEE_ID, O.C_COMPANY, O.C_ADDRESS,");
            strSql.Append(" O.CARRIER_ID, O.CARRIER_NAME, O.CREATED_DATE, O.ORDER_DATE, O.DELIVERY_DATE, O.REQUESTED_SHIP_DATE, O.ACTUAL_SHIP_DATE, O.REMARK");
            strSql.Append(" ) A INNER JOIN @_@ORDER_DETAIL OD ON A.ORDER_ID = OD.ORDER_ID");
            strSql.Append(" GROUP BY A.ORDER_ID, A.ORDER_STATUS, A.ORDER_TYPE, A.REFERENCE_NUM, A.EXTERN_ORDER_ID, A.CUSTOMER_ID,A.CUSTOMER_NAME, A.CUSTOMER_ADDRESS,");
            strSql.Append(" A.CARRIER_ID,A.CARRIER_NAME,A.CREATED_DATE,A.ORDER_DATE,A.DELIVERY_DATE,A.REQUESTED_SHIP_DATE,A.ACTUAL_SHIP_DATE,A.REMARK,");
            strSql.Append(" A.QTY,A.GROSS_WGT,A.[CUBE],A.PRICE");
            string sql = string.Empty;
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'").Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            if (!shipmentStatByOrderRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentStatByOrderRptQueryEntity.CurrentPage, shipmentStatByOrderRptQueryEntity.PageSize, shipmentStatByOrderRptQueryEntity.SortField, shipmentStatByOrderRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + shipmentStatByOrderRptQueryEntity.SortField + " " + shipmentStatByOrderRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetShipmentStatSplitCustomerRptDataSet(List<string> sqlWhere, ShipmentStatSplitCustomerRptQueryEntity shipmentStatSplitCustomerRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string strTableWhere = string.Empty;
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.OWNER_ID))
            {
                strTableWhere = " AND O.OWNER_ID " + shipmentStatSplitCustomerRptQueryEntity.OWNER_ID;
            }
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.SKU_ID))
            {
                strTableWhere = strTableWhere + " AND PD.SKU_ID " + shipmentStatSplitCustomerRptQueryEntity.SKU_ID;
            }
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.ORDER_TYPE))
            {
                strTableWhere = strTableWhere + " AND O.TYPE " + shipmentStatSplitCustomerRptQueryEntity.ORDER_TYPE;
            }
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.StartTime))
            {
                strTableWhere = strTableWhere + " AND OD.ACTUAL_SHIP_DATE >= '" + shipmentStatSplitCustomerRptQueryEntity.StartTime + "'";
            }
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.EndTime))
            {
                strTableWhere = strTableWhere + " AND OD.ACTUAL_SHIP_DATE <= '" + shipmentStatSplitCustomerRptQueryEntity.EndTime + "'";
            }
            if (!string.IsNullOrEmpty(shipmentStatSplitCustomerRptQueryEntity.CUSTOMER_ID))
            {
                strTableWhere = strTableWhere + " AND O.CONSIGNEE_ID " + shipmentStatSplitCustomerRptQueryEntity.CUSTOMER_ID;
            }
            strWhere = strTableWhere;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strCreateTable = new StringBuilder();
            StringBuilder strSql = new StringBuilder();
            if (shipmentStatSplitCustomerRptQueryEntity.IS_LOT == "Y")
            {
                strCreateTable.Append(" DECLARE @SQL VARCHAR(8000)  IF OBJECT_ID('TEMPDB.DBO.##TABLE') IS NOT NULL BEGIN  DROP TABLE ##TABLE END ");
                strCreateTable.Append(" SET @SQL = 'SELECT O.OWNER_ID as TABLE_OWNER_ID ,OD.SKU_ID AS TABLE_SKU_ID,PD.LOT AS TABLE_LOT '");
                strCreateTable.Append(" SELECT @SQL = @SQL + ' , SUM(CASE CONSIGNEE_ID WHEN ''' + CONSIGNEE_ID + ''' THEN PD.QTY ELSE 0 END) [' + CONSIGNEE_ID + ']' ");
                strCreateTable.Append(" FROM (SELECT DISTINCT  TOP 999999999 CONSIGNEE_ID FROM  @_@ORDERS O  INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID WHERE C_COMPANY IS NOT NULL AND STATUS IN ('PARTSHIPPED','SHIPPED') ORDER BY CONSIGNEE_ID ASC) AS A ");
                strCreateTable.Append(" SET @SQL = @SQL + ' INTO ##TABLE FROM  @_@ORDERS O INNER JOIN @_@ORDER_DETAIL OD  ON O.ORDER_ID =OD.ORDER_ID INNER JOIN  @_@PICK_DETAIL  PD ON PD.ORDER_ID =OD.ORDER_ID AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                strCreateTable.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID AND S.PACK_ID =PD.PACK_ID");
                strCreateTable.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                strCreateTable.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                strCreateTable.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT =LA.LOT");
                strCreateTable.Append("  LEFT JOIN @_@INV_LOT IL ON PD.LOT = IL.LOT ");
                strCreateTable.AppendFormat(" WHERE O.STATUS IN (''PARTSHIPPED'',''SHIPPED'') {0} GROUP BY O.CONSIGNEE_ID,O.OWNER_ID,OD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2, LA.PRODUCE_DATE,LA.EXPIRY_DATE,S.GROSS_WGT,S.[CUBE],S.DESCR2,PD.LOT,IL.UNIT_PRICE,U.UOM_DESCR ORDER BY O.CONSIGNEE_ID ASC'", strTableWhere.Replace("'", "''"));
                strCreateTable.Append(" EXEC(@SQL)   ");
                if (shipmentStatSplitCustomerRptQueryEntity.SHOW_DATE == "N")
                {
                    strSql.Append(" SELECT  A.*,T.* FROM (");
                    strSql.Append(" SELECT  PD.OWNER_ID AS OWNER_ID ,PD.SKU_ID AS SKU_ID,SUM(PD.QTY) AS QTY,PD.PACK_ID,S.DESCR AS SKU_DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2 AS SKU_UDF2,S.DESCR2 AS SKU_DESCR2, ");
                    strSql.Append(" LA.PRODUCE_DATE,LA.EXPIRY_DATE, (S.GROSS_WGT * SUM(PD.QTY)) AS TOTAL_WGT, (S.[CUBE] * SUM(PD.QTY)) AS TOTAL_CUBE,PD.LOT,IL.UNIT_PRICE AS UNIT_PRICE ,U.UOM_DESCR, O.CONSIGNEE_ID ");
                    strSql.Append(" FROM @_@PICK_DETAIL PD");
                    strSql.Append(" LEFT JOIN  @_@ORDER_DETAIL OD ON PD.ORDER_ID=OD.ORDER_ID  AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                    strSql.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID AND S.PACK_ID =PD.PACK_ID");
                    strSql.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                    strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                    strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT =LA.LOT");
                    strSql.Append(" LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON PD.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID");
                    strSql.Append("  LEFT JOIN @_@INV_LOT IL ON PD.LOT = IL.LOT ");
                    strSql.AppendFormat(" WHERE PD.STATUS='Shipped' {0} ", strWhere);
                    strSql.Append(" GROUP BY O.CONSIGNEE_ID,PD.OWNER_ID,PD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2, LA.PRODUCE_DATE,LA.EXPIRY_DATE,S.GROSS_WGT,S.[CUBE],S.DESCR2,PD.LOT,IL.UNIT_PRICE,U.UOM_DESCR  ");
                    strSql.Append("   ) A ");
                    strSql.Append("  LEFT JOIN ##Table T ON A.OWNER_ID = T.TABLE_OWNER_ID AND A.SKU_ID =T.TABLE_SKU_ID AND A.LOT = T.TABLE_LOT   ");
                }
                else
                {
                    strSql.Append(" SELECT  A.*,T.* FROM (");
                    strSql.Append(" SELECT  PD.OWNER_ID AS OWNER_ID ,PD.SKU_ID AS SKU_ID,SUM(PD.QTY) AS QTY,PD.PACK_ID,Convert(varchar,O.ACTUAL_SHIP_DATE,102) AS ACTUAL_SHIP_DATE,S.DESCR AS SKU_DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2 AS SKU_UDF2,S.DESCR2 AS SKU_DESCR2, ");
                    strSql.Append(" LA.PRODUCE_DATE,LA.EXPIRY_DATE, (S.GROSS_WGT * SUM(PD.QTY)) AS TOTAL_WGT, (S.[CUBE] * SUM(PD.QTY)) AS TOTAL_CUBE,PD.LOT,IL.UNIT_PRICE,U.UOM_DESCR, O.CONSIGNEE_ID  ");
                    strSql.Append(" FROM @_@PICK_DETAIL PD");
                    strSql.Append(" LEFT JOIN  @_@ORDER_DETAIL OD ON PD.ORDER_ID=OD.ORDER_ID  AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                    strSql.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID");
                    strSql.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                    strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                    strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT =LA.LOT");
                    strSql.Append(" LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON PD.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID");
                    strSql.Append("  LEFT JOIN @_@INV_LOT IL ON PD.LOT = IL.LOT ");
                    strSql.AppendFormat(" WHERE PD.STATUS='Shipped' {0} ", strWhere);
                    strSql.Append(" GROUP BY O.CONSIGNEE_ID,PD.OWNER_ID,PD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2, LA.PRODUCE_DATE,LA.EXPIRY_DATE,S.GROSS_WGT,S.[CUBE],S.DESCR2,PD.LOT,Convert(varchar,O.ACTUAL_SHIP_DATE,102),IL.UNIT_PRICE,U.UOM_DESCR  ");
                    strSql.Append("  ) A ");
                    strSql.Append("  LEFT JOIN ##Table T ON A.OWNER_ID = T.TABLE_OWNER_ID AND A.SKU_ID =T.TABLE_SKU_ID AND A.LOT = T.TABLE_LOT ");
                }
            }
            else
            {
                strCreateTable.Append(" DECLARE @SQL VARCHAR(8000)  IF OBJECT_ID('TEMPDB.DBO.##TABLE') IS NOT NULL BEGIN  DROP TABLE ##TABLE END ");
                strCreateTable.Append(" SET @SQL = 'SELECT O.OWNER_ID as TABLE_OWNER_ID ,OD.SKU_ID AS TABLE_SKU_ID '");
                strCreateTable.Append(" SELECT @SQL = @SQL + ' , SUM(CASE CONSIGNEE_ID WHEN ''' + CONSIGNEE_ID + ''' THEN PD.QTY ELSE 0 END) [' + CONSIGNEE_ID + ']' ");
                strCreateTable.Append(" FROM (SELECT DISTINCT  TOP 999999999 CONSIGNEE_ID  FROM  @_@ORDERS O INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID WHERE C_COMPANY IS NOT NULL AND STATUS IN ('PARTSHIPPED','SHIPPED') ORDER BY CONSIGNEE_ID ASC) AS A ");
                strCreateTable.Append(" SET @SQL = @SQL + ' INTO ##TABLE FROM  @_@ORDERS O INNER JOIN @_@ORDER_DETAIL OD  ON O.ORDER_ID =OD.ORDER_ID INNER JOIN  @_@PICK_DETAIL  PD ON PD.ORDER_ID =OD.ORDER_ID AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                strCreateTable.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID");
                strCreateTable.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                strCreateTable.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                strCreateTable.AppendFormat("  WHERE O.STATUS IN (''PARTSHIPPED'',''SHIPPED'')  {0} GROUP BY O.CONSIGNEE_ID,O.OWNER_ID,OD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2,S.GROSS_WGT,S.[CUBE],S.DESCR2,U.UOM_DESCR ORDER BY O.CONSIGNEE_ID ASC'", strTableWhere.Replace("'", "''"));
                strCreateTable.Append(" EXEC(@SQL)   ");
                if (shipmentStatSplitCustomerRptQueryEntity.SHOW_DATE == "N")
                {
                    strSql.Append(" SELECT  A.*,T.* FROM (");
                    strSql.Append(" SELECT  PD.OWNER_ID AS OWNER_ID,PD.SKU_ID AS SKU_ID,SUM(PD.QTY) AS QTY,PD.PACK_ID,S.DESCR AS SKU_DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2 AS SKU_UDF2,S.DESCR2 AS SKU_DESCR2, ");
                    strSql.Append(" (S.GROSS_WGT *SUM(PD.QTY)) AS TOTAL_WGT, (S.[CUBE] * SUM(PD.QTY)) AS TOTAL_CUBE,U.UOM_DESCR, O.CONSIGNEE_ID ");
                    strSql.Append(" FROM @_@PICK_DETAIL PD");
                    strSql.Append(" LEFT JOIN  @_@ORDER_DETAIL OD ON PD.ORDER_ID=OD.ORDER_ID  AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                    strSql.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID");
                    strSql.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                    strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                    strSql.Append(" LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON PD.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID");
                    strSql.Append("  LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT");
                    strSql.AppendFormat(" WHERE PD.STATUS='Shipped' {0} ", strTableWhere);
                    strSql.Append(" GROUP BY O.CONSIGNEE_ID,PD.OWNER_ID,PD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2,S.GROSS_WGT,S.[CUBE],S.DESCR2,U.UOM_DESCR  ");
                    strSql.Append("  ) A ");
                    strSql.Append(" LEFT JOIN ##Table T ON A.OWNER_ID = T.TABLE_OWNER_ID AND A.SKU_ID =T.TABLE_SKU_ID  ");
                }
                else
                {
                    strSql.Append(" SELECT  A.*,T.* FROM (");
                    strSql.Append(" SELECT  PD.OWNER_ID AS OWNER_ID,PD.SKU_ID AS SKU_ID,SUM(PD.QTY) AS QTY,PD.PACK_ID,Convert(varchar,O.ACTUAL_SHIP_DATE,102) AS ACTUAL_SHIP_DATE ,S.DESCR AS SKU_DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2 AS SKU_UDF2,S.DESCR2 AS SKU_DESCR2, ");
                    strSql.Append(" (S.GROSS_WGT *SUM(PD.QTY)) AS TOTAL_WGT, (S.[CUBE] * SUM(PD.QTY)) AS TOTAL_CUBE ,U.UOM_DESCR, O.CONSIGNEE_ID");
                    strSql.Append(" FROM @_@PICK_DETAIL PD");
                    strSql.Append(" LEFT JOIN  @_@ORDER_DETAIL OD ON PD.ORDER_ID=OD.ORDER_ID  AND PD.ORDER_LINE_ID = OD.LINE_ID ");
                    strSql.Append(" LEFT JOIN @_@SKU  S ON PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID");
                    strSql.Append(" LEFT JOIN  @_@PACK PACK ON S.PACK_ID = PACK.PACK_ID ");
                    strSql.Append(" LEFT JOIN  @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
                    strSql.Append(" LEFT JOIN @_@ORDERS O ON PD.ORDER_ID = O.ORDER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON PD.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
                    strSql.Append("  INNER JOIN SYSADM.USER_CUSTOMER UC ON O.CONSIGNEE_ID = UC.CUSTOMER_ID AND UC.USER_ID = @USER_ID");
                    strSql.Append("  LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT");
                    strSql.AppendFormat(" WHERE PD.STATUS='Shipped' {0} ", strTableWhere);
                    strSql.Append(" GROUP BY O.CONSIGNEE_ID,PD.OWNER_ID,PD.SKU_ID,PD.PACK_ID,S.DESCR,S.SKU_CLASS_ID,S.SKU_GROUP,S.UDF2,S.GROSS_WGT,S.[CUBE],S.DESCR2,Convert(varchar,O.ACTUAL_SHIP_DATE,102),U.UOM_DESCR ");
                    strSql.Append("  ) A ");
                    strSql.Append(" LEFT JOIN ##Table T ON A.OWNER_ID = T.TABLE_OWNER_ID AND A.SKU_ID =T.TABLE_SKU_ID  ");
                }
            }
            string sql = string.Empty;
            string sqlCreateTable = string.Empty;
            sqlCreateTable = strCreateTable.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            if (!shipmentStatSplitCustomerRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, shipmentStatSplitCustomerRptQueryEntity.CurrentPage, shipmentStatSplitCustomerRptQueryEntity.PageSize, shipmentStatSplitCustomerRptQueryEntity.SortField, shipmentStatSplitCustomerRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY  " + shipmentStatSplitCustomerRptQueryEntity.SortField + " " + shipmentStatSplitCustomerRptQueryEntity.SortDirection;
            }
            sql = sql + "   IF OBJECT_ID('TEMPDB.DBO.##TABLE') IS NOT NULL BEGIN  DROP TABLE ##TABLE END ";
            return DBHelper.ExecuteDataSet(CommandType.Text, sqlCreateTable + sql);
        }

        public DataSet GetStatementRptDataSet(List<string> sqlWhere, StatementRptQueryEntity statementRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT A.STATEMENT_DATE,A.CREATED_DATE,A.OWNER_ID,A.COMPANY,SUM(A.TOTAL_AMOUNT) AS TOTAL_AMOUNT,  ");
            strSql.Append("  SUM(A.INVOICE_AMOUNT) AS INVOICE_AMOUNT,SUM(A.PAY_AMOUNT) AS PAY_AMOUNT,SUM(A.LAST_PAY_AMOUNT) AS LAST_PAY_AMOUNT,SUM(A.LAST_INVOICE_AMOUNT) AS LAST_INVOICE_AMOUNT,  ");
            strSql.Append("  (SELECT CONVERT(FLOAT,ISNULL(SUM(TOTAL_AMOUNT-PAY_AMOUNT),0)) FROM @_@STATEMENT WHERE BILLING_OBJECT = 'Owner' AND DUE_FROM_TO = 'DueFrom' AND BILLING_OBJECT_ID = A.OWNER_ID AND CREATED_DATE < A.CREATED_DATE) AS LAST_TOTAL_AMOUNT  ");
            strSql.Append("  FROM (  ");
            strSql.Append("  SELECT CONVERT(VARCHAR(4),YEAR(S.CREATED_DATE)) + '年' + CONVERT(VARCHAR(4),MONTH(S.CREATED_DATE)) + '月' AS STATEMENT_DATE,  ");
            strSql.Append("  CONVERT(DATETIME,CONVERT(VARCHAR(4),YEAR(S.CREATED_DATE)) + '-' + CONVERT(VARCHAR(4),MONTH(S.CREATED_DATE)) + '-01') AS CREATED_DATE,  ");
            strSql.Append("  O.OWNER_ID,O.COMPANY,CONVERT(FLOAT,S.TOTAL_AMOUNT) AS TOTAL_AMOUNT,CONVERT(FLOAT,S.INVOICE_AMOUNT) AS INVOICE_AMOUNT,CONVERT(FLOAT,S.PAY_AMOUNT) AS PAY_AMOUNT,CONVERT(FLOAT,S.INVOICE_AMOUNT-S.PAY_AMOUNT) AS LAST_PAY_AMOUNT,CONVERT(FLOAT,S.TOTAL_AMOUNT-S.INVOICE_AMOUNT) AS LAST_INVOICE_AMOUNT  ");
            strSql.Append("  FROM @_@STATEMENT S LEFT JOIN @_@OWNER O ON O.OWNER_ID = S.BILLING_OBJECT_ID  ");
            strSql.Append("  WHERE S.BILLING_OBJECT = 'Owner' AND S.DUE_FROM_TO = 'DueFrom'  ");
            strSql.Append("  ) A  INNER JOIN SYSADM.USER_OWNER UO ON A.OWNER_ID = UO.OWNER_ID AND UO.[USER_ID] = @USER_ID");
            strSql.AppendFormat("  WHERE  1=1   {0}  ", strWhere);
            strSql.Append("  GROUP BY A.STATEMENT_DATE,A.CREATED_DATE,A.OWNER_ID,A.COMPANY  ");
            strSql = strSql.Replace("@_@", whLoginID).Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            if (!statementRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), statementRptQueryEntity.CurrentPage, statementRptQueryEntity.PageSize, statementRptQueryEntity.SortField, statementRptQueryEntity.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + statementRptQueryEntity.SortField + " " + statementRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetStockRptInfo(List<string> sqlWhere, StockRptQueryEntity stockRptQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT DISTINCT * FROM (  ");
            strSql.Append(" SELECT DISTINCT ILLL.LOT,ILLL.LOC,ILLL.LPN_ID,SKU.OWNER_ID,ILLL.SKU_ID, SKU.DESCR, SKU.SKU_CLASS_ID,");
            strSql.Append(" ILLL.ALLOCATED_QTY,  ILLL.PICKED_QTY,PACK.PACK_UOM1, ILLL.QTY * SKU.GROSS_WGT AS GROSS_WGT, ");
            strSql.Append(" ILLL.QTY * SKU.[CUBE] AS CUBE,ILLL.STATUS, LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04,  LA.LOT_ATTR05, LA.LOT_ATTR06,");
            strSql.Append(" LA.LOT_ATTR07, LA.LOT_ATTR08,LAC.DESCR AS LOT_ATTR09, LA.LOT_ATTR10, LA.PRODUCE_DATE, LA.EXPIRY_DATE, ");
            strSql.Append(" LA.EXTERNAL_LOT,LA.RECEIPT_DATE, ILLL.QTY,PO.CREATED_DATE AS PO_DATE, ");
            strSql.Append(" ILLL.QTY - ILLL.ALLOCATED_QTY - ILLL.PICKED_QTY - ILLL.EXPECTED_QTY - ILLL.PICKINPROCESS_QTY - ILLL.PENDING_MOVE_IN - ILLL.ARCHIVE_QTY AS CANUSE_QTY, LA.VENDOR_ID ,IL.UNIT_PRICE,SKU.SKU_STYLE,U.UOM_DESCR,SKU.PACK_ID,");
            strSql.Append(" (SELECT TOP 1 ALT_SKU_ID FROM @_@ALTERNATE_SKU  WHERE OWNER_ID=SKU.OWNER_ID AND SKU_ID= SKU.SKU_ID AND TYPE ='Vendor') AS ALT_SKU_ID ");
            strSql.Append(" FROM @_@INV_LOT_LOC_LPN ILLL ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON ILLL.LOT = LA.LOT ");
            strSql.Append(" LEFT JOIN @_@SKU SKU ON LA.OWNER_ID = SKU.OWNER_ID AND LA.SKU_ID = SKU.SKU_ID ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON LA.LOT_ATTR10 = R.RECEIPT_ID ");
            strSql.Append(" LEFT JOIN @_@PURCHASE_ORDER PO ON R.PO_ID=PO.PO_ID");
            strSql.Append(" LEFT JOIN @_@PACK PACK ON SKU.PACK_ID = PACK.PACK_ID ");
            strSql.Append(" LEFT JOIN @_@UOM U ON U.UOM_ID = PACK.PACK_UOM1 ");
            strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
            strSql.Append(" LEFT JOIN @_@INV_LOT IL ON ILLL.LOT = IL.LOT");
            strSql.Append(" WHERE ILLL.OWNER_ID IN (SELECT OWNER_ID FROM SYSADM.USER_OWNER WHERE USER_ID = @USER_ID) ");
            strSql.Append(" AND (LA.VENDOR_ID IN (SELECT VENDOR_ID FROM SYSADM.USER_VENDOR WHERE USER_ID = @USER_ID) OR LA.VENDOR_ID = '' OR LA.VENDOR_ID IS NULL) ");
            if (stockRptQuery.ISHISTORY.ToUpper() == "N")
            {
                strSql.Append(" AND ILLL.QTY > 0 ");
            }
            strSql.Append(" ) TEMP");
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    sql = sql + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    sql = sql + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!stockRptQuery.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, stockRptQuery.CurrentPage, stockRptQuery.PageSize, stockRptQuery.SortField, stockRptQuery.SortDirection).Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + stockRptQuery.SortField + " " + stockRptQuery.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetVendorReturnDetailRptDataSet(List<string> sqlWhere, VendorReturnDetailRptQueryEntity vendorReturnDetailRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT O.CONSIGNEE_ID AS VENDOR_ID,O.C_COMPANY AS VENDOR_NAME,O.ORDER_DATE AS ORDER_DATE,O.OWNER_ID AS OWNER_ID,PD.SKU_ID AS SKU_ID,S.DESCR AS SKU_DESCR,S.PACK_ID AS PACK_ID,U.UOM_DESCR,SUM(PD.QTY) AS QTY, ");
            strSql.Append("  IL.UNIT_PRICE AS UNIT_PRICE, IL.UNIT_PRICE * SUM(PD.QTY) AS TOTAL_PRICE,  O.REMARK AS REMARK,PD.ORDER_ID AS ORDER_ID,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.EXTERNAL_LOT AS EXTERNAL_LOT,S.SKU_CLASS_ID AS SKU_CLASS_ID,S.SKU_GROUP AS SKU_GROUP,S.UDF2 AS SKU_UDF2,S.DESCR2 AS SKU_DESCR2, ");
            strSql.Append("  LA.LOT AS LOT,LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03,LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05,LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,LA.LOT_ATTR10 AS LOT_ATTR10 ");
            strSql.Append("   FROM @_@PICK_DETAIL  PD  INNER JOIN  @_@ORDERS O   ON O.ORDER_ID = PD.ORDER_ID   INNER JOIN @_@SKU S  ON   PD.OWNER_ID =S.OWNER_ID AND PD.SKU_ID = S.SKU_ID LEFT JOIN @_@PACK P ON P.PACK_ID = S.PACK_ID  LEFT JOIN @_@UOM U ON U.UOM_ID = P.PACK_UOM1  LEFT JOIN  @_@INV_LOT IL ON IL.LOT = PD.LOT  LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT  LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'");
            strSql.Append("  INNER JOIN SYSADM.USER_OWNER UO ON PD.OWNER_ID = UO.OWNER_ID AND UO.USER_ID = @USER_ID ");
            strSql.Append("  WHERE  O.TYPE ='RETURN ' AND PD.STATUS ='Shipped'");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" GROUP BY O.CONSIGNEE_ID,O.C_COMPANY ,O.ORDER_DATE,O.OWNER_ID,PD.SKU_ID,S.DESCR,S.PACK_ID,IL.UNIT_PRICE,O.REMARK,PD.ORDER_ID,IL.UNIT_PRICE,LA.LOT,LA.LOT_ATTR01,LA.LOT_ATTR02,LA.LOT_ATTR03,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06,LA.LOT_ATTR07,LA.LOT_ATTR08,LAC.DESCR ,LA.LOT_ATTR10,LA.PRODUCE_DATE,LA.EXPIRY_DATE,LA.EXTERNAL_LOT,S.SKU_GROUP,S.UDF2 ,S.DESCR2,S.SKU_CLASS_ID,U.UOM_DESCR ");
            string sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'");
            if (!vendorReturnDetailRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, vendorReturnDetailRptQueryEntity.CurrentPage, vendorReturnDetailRptQueryEntity.PageSize, vendorReturnDetailRptQueryEntity.SortField, vendorReturnDetailRptQueryEntity.SortDirection);
            }
            else
            {
                sql = sql + " ORDER BY " + vendorReturnDetailRptQueryEntity.SortField + " " + vendorReturnDetailRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetWarehouseTransferRptDateSet(List<string> sqlWhere, WarehouseTransferRptQueryEntity warehouseTransferRptQueryEntity, PubParasInfo pubParasInfo, string whLoginID)
        {
            string StrGroupby = string.Empty;
            StringBuilder strSql = new StringBuilder();
            if (warehouseTransferRptQueryEntity.ShowLot == "N")
            {
                if (warehouseTransferRptQueryEntity.ShowDate == "Y")
                {
                    strSql.Append(" SELECT I.INTRANSIT_ID, I.ORDER_ID,I.RECEIPT_ID,I.ACTUAL_SHIP_DATE, SRCDC.WH_DB_DESC AS SRC_WH_DB_DESC ,DESTCDC.WH_DB_DESC AS DEST_WH_DB_DESC,I.OWNER_ID AS OWNER_ID,ID.SKU_ID AS SKU_ID, S.DESCR AS DESCR,S.PACK_ID AS PACK_ID,S.SKU_GROUP AS SKU_GROUP,S.SKU_CLASS_ID,S.DESCR2 AS DESCR2,S.UDF2 AS UDF2,SUM(PD.QTY) AS QTY FROM  @_@INTRANSIT_DETAIL  ID");
                    strSql.Append(" LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID=I.INTRANSIT_ID");
                    strSql.Append(" LEFT JOIN @_@SKU S ON S.SKU_ID=ID.SKU_ID  AND S.OWNER_ID=ID.OWNER_ID");
                    strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG SRCDC ON I.SRC_WH_DB_ID=SRCDC.WH_DB_ID");
                    strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG DESTCDC ON I.DEST_WH_DB_ID=DESTCDC.WH_DB_ID ");
                    strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON I.ORDER_ID =PD.ORDER_ID AND ID.ORDER_LINE_ID=PD.ORDER_LINE_ID");
                    strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT  WHERE PD.STATUS ='Shipped' ");
                    StrGroupby = " GROUP BY I.INTRANSIT_ID, I.ORDER_ID,I.RECEIPT_ID,I.ACTUAL_SHIP_DATE, SRCDC.WH_DB_DESC ,DESTCDC.WH_DB_DESC ,I.OWNER_ID,S.SKU_CLASS_ID ,ID.SKU_ID, S.DESCR ,S.PACK_ID ,S.SKU_GROUP ,S.DESCR2 ,S.UDF2";
                }
                else
                {
                    strSql.Append(" SELECT SRCDC.WH_DB_DESC AS SRC_WH_DB_DESC ,DESTCDC.WH_DB_DESC AS DEST_WH_DB_DESC,I.OWNER_ID AS OWNER_ID,ID.SKU_ID AS SKU_ID, S.DESCR AS DESCR,S.SKU_CLASS_ID,S.PACK_ID AS PACK_ID,S.SKU_GROUP AS SKU_GROUP,S.DESCR2 AS DESCR2,S.UDF2 AS UDF2,SUM(PD.QTY) AS QTY FROM  @_@INTRANSIT_DETAIL  ID");
                    strSql.Append(" LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID=I.INTRANSIT_ID");
                    strSql.Append(" LEFT JOIN @_@SKU S ON S.SKU_ID=ID.SKU_ID  AND S.OWNER_ID=ID.OWNER_ID");
                    strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG SRCDC ON I.SRC_WH_DB_ID=SRCDC.WH_DB_ID");
                    strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG DESTCDC ON I.DEST_WH_DB_ID=DESTCDC.WH_DB_ID  ");
                    strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON I.ORDER_ID =PD.ORDER_ID AND ID.ORDER_LINE_ID=PD.ORDER_LINE_ID");
                    strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT   WHERE PD.STATUS ='Shipped'");
                    StrGroupby = " GROUP BY SRCDC.WH_DB_DESC  ,DESTCDC.WH_DB_DESC ,I.OWNER_ID ,ID.SKU_ID, S.DESCR ,S.PACK_ID,S.SKU_CLASS_ID ,S.SKU_GROUP ,S.DESCR2 ,S.UDF2";
                }
            }
            else if (warehouseTransferRptQueryEntity.ShowDate == "Y")
            {
                strSql.Append(" SELECT I.INTRANSIT_ID, I.ORDER_ID,I.RECEIPT_ID,I.ACTUAL_SHIP_DATE,  SRCDC.WH_DB_DESC AS SRC_WH_DB_DESC ,DESTCDC.WH_DB_DESC AS DEST_WH_DB_DESC,I.OWNER_ID AS OWNER_ID,ID.SKU_ID AS SKU_ID, S.DESCR AS DESCR,S.SKU_CLASS_ID,S.PACK_ID AS PACK_ID,S.SKU_GROUP AS SKU_GROUP,S.DESCR2 AS DESCR2,S.UDF2 AS UDF2, SUM(PD.QTY) AS QTY, ");
                strSql.Append(" PD.LOT AS LOT,LA.EXTERNAL_LOT AS EXTERNAL_LOT,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.VENDOR_ID AS VENDOR_ID,LA.RECEIPT_DATE AS RECEIPT_DATE,LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03,LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05,LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,LA.LOT_ATTR10 AS LOT_ATTR10 ");
                strSql.Append(" FROM  @_@INTRANSIT_DETAIL  ID");
                strSql.Append(" LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID=I.INTRANSIT_ID");
                strSql.Append(" LEFT JOIN @_@SKU S ON S.SKU_ID=ID.SKU_ID AND S.OWNER_ID=ID.OWNER_ID");
                strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG SRCDC ON I.SRC_WH_DB_ID=SRCDC.WH_DB_ID");
                strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG DESTCDC ON I.DEST_WH_DB_ID=DESTCDC.WH_DB_ID ");
                strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON I.ORDER_ID =PD.ORDER_ID AND ID.ORDER_LINE_ID=PD.ORDER_LINE_ID");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT ");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' WHERE PD.STATUS ='Shipped' ");
                StrGroupby = "  GROUP BY I.INTRANSIT_ID, I.ORDER_ID,I.RECEIPT_ID,I.ACTUAL_SHIP_DATE, SRCDC.WH_DB_DESC ,S.SKU_CLASS_ID ,DESTCDC.WH_DB_DESC ,I.OWNER_ID ,ID.SKU_ID, S.DESCR ,S.PACK_ID ,S.SKU_GROUP ,S.DESCR2 ,S.SKU_CLASS_ID ,S.UDF2,PD.LOT, LA.EXTERNAL_LOT,LA.PRODUCE_DATE,LA.EXPIRY_DATE,LA.VENDOR_ID,LA.RECEIPT_DATE,LA.LOT_ATTR01,LA.LOT_ATTR02,LA.LOT_ATTR03,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06,LA.LOT_ATTR07,LA.LOT_ATTR08,LAC.DESCR,LA.LOT_ATTR10";
            }
            else
            {
                strSql.Append(" SELECT   SRCDC.WH_DB_DESC AS SRC_WH_DB_DESC ,DESTCDC.WH_DB_DESC AS DEST_WH_DB_DESC,I.OWNER_ID AS OWNER_ID,ID.SKU_ID AS SKU_ID, S.DESCR AS DESCR,S.PACK_ID AS PACK_ID,S.SKU_CLASS_ID,S.SKU_GROUP AS SKU_GROUP,S.DESCR2 AS DESCR2,S.UDF2 AS UDF2, SUM(PD.QTY) AS QTY, ");
                strSql.Append(" PD.LOT AS LOT,LA.EXTERNAL_LOT AS EXTERNAL_LOT,LA.PRODUCE_DATE AS PRODUCE_DATE,LA.EXPIRY_DATE AS EXPIRY_DATE,LA.VENDOR_ID AS VENDOR_ID,LA.RECEIPT_DATE AS RECEIPT_DATE,LA.LOT_ATTR01 AS LOT_ATTR01,LA.LOT_ATTR02 AS LOT_ATTR02,LA.LOT_ATTR03 AS LOT_ATTR03,LA.LOT_ATTR04 AS LOT_ATTR04,LA.LOT_ATTR05 AS LOT_ATTR05,LA.LOT_ATTR06 AS LOT_ATTR06,LA.LOT_ATTR07 AS LOT_ATTR07,LA.LOT_ATTR08 AS LOT_ATTR08,LAC.DESCR AS LOT_ATTR09,LA.LOT_ATTR10 AS LOT_ATTR10 ");
                strSql.Append(" FROM  @_@INTRANSIT_DETAIL  ID");
                strSql.Append(" LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID=I.INTRANSIT_ID");
                strSql.Append(" LEFT JOIN @_@SKU S ON S.SKU_ID=ID.SKU_ID AND S.OWNER_ID=ID.OWNER_ID");
                strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG SRCDC ON I.SRC_WH_DB_ID=SRCDC.WH_DB_ID");
                strSql.Append(" LEFT JOIN SYSADM.DB_CONFIG DESTCDC ON I.DEST_WH_DB_ID=DESTCDC.WH_DB_ID ");
                strSql.Append(" LEFT JOIN @_@PICK_DETAIL PD ON I.ORDER_ID =PD.ORDER_ID AND ID.ORDER_LINE_ID=PD.ORDER_LINE_ID");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE LA ON PD.LOT=LA.LOT ");
                strSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性'  WHERE PD.STATUS ='Shipped' ");
                StrGroupby = "GROUP BY SRCDC.WH_DB_DESC  ,DESTCDC.WH_DB_DESC ,I.OWNER_ID ,ID.SKU_ID, S.DESCR ,S.PACK_ID,S.SKU_CLASS_ID ,S.SKU_GROUP ,S.DESCR2 ,S.UDF2,PD.LOT, LA.EXTERNAL_LOT,LA.PRODUCE_DATE,LA.EXPIRY_DATE,LA.VENDOR_ID,LA.RECEIPT_DATE,LA.LOT_ATTR01,LA.LOT_ATTR02,LA.LOT_ATTR03,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06,LA.LOT_ATTR07,LA.LOT_ATTR08,LAC.DESCR,LA.LOT_ATTR10";
            }
            string sql = strSql.ToString().Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                sql = sql + " AND " + sqlWhere[i].ToString();
            }
            sql = sql + StrGroupby;
            if (!warehouseTransferRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(sql, warehouseTransferRptQueryEntity.CurrentPage, warehouseTransferRptQueryEntity.PageSize, warehouseTransferRptQueryEntity.SortField, warehouseTransferRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = sql.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + warehouseTransferRptQueryEntity.SortField + " " + warehouseTransferRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetWorkClassRptDataSet(List<string> sqlWhere, WorkClassRptQueryEntity workClassRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = string.Empty;
            string strWhere = string.Empty;
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strWhere = strWhere + " AND " + sqlWhere[i].ToString();
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT WORK_DRIVER,WORK_DRIVER_NAME,WORK_TYPE,WORK_TYPE_D,IS_HOLIDAY,CASE IS_HOLIDAY WHEN 'Y' THEN '是' WHEN 'N' THEN '否' END AS IS_HOLIDAY_D, BILLING_TYPE,SUM(BILLING_QTY) AS BILLING_QTY,SUM(AMOUNT) AS AMOUNT,'' AS REMARK ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT A.CREATED_DATE,A.ORDER_ID,A.WORK_DRIVER,A.WORK_CLASS_ID,A.FORKLIFT_DRIVER,A.WORK_TYPE,A.IS_HOLIDAY,A.OWNER_ID,A.SKU_ID,A.QTY,A.[CASE],A.PALLET,T.[TEXT] AS WORK_TYPE_D, ");
            strSql.Append(" CASE ISNULL(E.EMPLOYEE_NAME,'') WHEN '' THEN WORK_DRIVER ELSE E.EMPLOYEE_NAME END AS WORK_DRIVER_NAME, ");
            strSql.Append(" CASE RD.CHARGE_UNIT WHEN 'Quantity' THEN '件' WHEN 'Weight' THEN '吨' WHEN 'Measurement' THEN '立方' ");
            strSql.Append(" WHEN 'BillingTon' THEN '计费吨' WHEN 'Area' THEN '面积' WHEN 'Area' THEN '固定费用' ");
            strSql.Append(" WHEN 'Location' THEN '货位' WHEN 'Pallet' THEN '托盘数'  ");
            strSql.Append(" WHEN 'BillingPallet' THEN '计费托' WHEN 'BillingCase' THEN '计费箱'  ");
            strSql.Append(" END AS BILLING_TYPE, ");
            strSql.Append(" CASE RD.CHARGE_UNIT WHEN 'Quantity' THEN QTY ");
            strSql.Append(" WHEN 'Weight' THEN SKU.GROSS_WGT*QTY ");
            strSql.Append(" WHEN 'Measurement' THEN SKU.[CUBE]*QTY ");
            strSql.Append(" WHEN 'BillingTon' THEN (CASE WHEN SKU.GROSS_WGT > SKU.[CUBE] THEN SKU.GROSS_WGT ELSE SKU.[CUBE] END)*QTY ");
            strSql.Append(" WHEN 'ATM' THEN SKU.COST_PRICE*QTY ");
            strSql.Append(" WHEN 'Area' THEN SKU.LENGTH*SKU.WIDTH*QTY ");
            strSql.Append(" WHEN 'FixedRate' THEN RD.FIXED_RATE ");
            strSql.Append(" WHEN 'Pallet' THEN 0 ");
            strSql.Append(" WHEN 'Location' THEN 0 ");
            strSql.Append(" WHEN 'BillingPallet' THEN ISNULL([PALLET],0) ");
            strSql.Append(" WHEN 'BillingCase' THEN ISNULL([CASE],0) ");
            strSql.Append(" END AS BILLING_QTY, ");
            strSql.Append(" RATE.RATE_ID,RD.FIXED_RATE,CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END AS CHARGE_PER_UNIT, ");
            strSql.Append(" CASE RD.CHARGE_UNIT  ");
            strSql.Append(" WHEN 'Quantity' THEN QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'Weight' THEN SKU.GROSS_WGT*QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'Measurement' THEN SKU.[CUBE]*QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'BillingTon' THEN (CASE WHEN SKU.GROSS_WGT > SKU.[CUBE] THEN SKU.GROSS_WGT ELSE SKU.[CUBE] END)*QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'ATM' THEN SKU.COST_PRICE*QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'Area' THEN SKU.LENGTH*SKU.WIDTH*QTY*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'FixedRate' THEN RD.FIXED_RATE ");
            strSql.Append(" WHEN 'Pallet' THEN 0 ");
            strSql.Append(" WHEN 'Location' THEN 0 ");
            strSql.Append(" WHEN 'BillingPallet' THEN ISNULL([PALLET],0)*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" WHEN 'BillingCase' THEN ISNULL([CASE],0)*RD.FIXED_RATE/(CASE RD.CHARGE_PER_UNIT WHEN 0 THEN 1 ELSE RD.CHARGE_PER_UNIT END) ");
            strSql.Append(" END AS AMOUNT ");
            strSql.Append(" FROM ");
            strSql.Append(" ( ");
            strSql.Append(" SELECT 'InBound' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS AS WORK_DRIVER,MPR.WORK_CLASS AS WORK_CLASS_ID,'' AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID, ");
            strSql.Append(" CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END AS SKU_ID, ");
            strSql.Append(" CASE R.IS_PALLETIZED WHEN 'Y' THEN SUM(RDL.RECEIVED_QTY) ELSE SUM(RD.RECEIVED_QTY) END AS QTY, ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.[CASE],0)) AS [CASE] FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'ASN' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = (CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END) )  AS [CASE], ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.PALLET,0)) AS PALLET FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'ASN' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = (CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END) )  AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@RECEIPT_DETAIL RD ON RD.RECEIPT_ID = R.RECEIPT_ID AND R.IS_PALLETIZED <> 'Y' ");
            strSql.Append(" LEFT JOIN @_@RECEIPT_DETAIL_LPN RDL ON RDL.RECEIPT_ID = R.RECEIPT_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'ASN' AND ISNULL(MPR.WORK_CLASS,'')<>'' AND R.STATUS IN ('ReceivedComplete','Closed') ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,RDL.SKU_ID,R.IS_PALLETIZED ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'InBound' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER AS WORK_DRIVER,''  AS WORK_CLASS_ID,MPR.FORKLIFT_DRIVER AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID, ");
            strSql.Append(" CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END AS SKU_ID, ");
            strSql.Append(" CASE R.IS_PALLETIZED WHEN 'Y' THEN SUM(RDL.RECEIVED_QTY) ELSE SUM(RD.RECEIVED_QTY) END AS QTY, ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.[CASE],0)) AS [CASE] FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'ASN' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = (CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END) )  AS [CASE], ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.PALLET,0)) AS PALLET FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'ASN' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = (CASE R.IS_PALLETIZED WHEN 'Y' THEN RDL.SKU_ID ELSE RD.SKU_ID END) )  AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@RECEIPT R ON R.RECEIPT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@RECEIPT_DETAIL RD ON RD.RECEIPT_ID = R.RECEIPT_ID AND R.IS_PALLETIZED <> 'Y' ");
            strSql.Append(" LEFT JOIN @_@RECEIPT_DETAIL_LPN RDL ON RDL.RECEIPT_ID = R.RECEIPT_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'ASN' AND ISNULL(MPR.FORKLIFT_DRIVER,'')<>'' AND R.STATUS IN ('ReceivedComplete','Closed')  ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,RDL.SKU_ID,R.IS_PALLETIZED ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'OutBound' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS AS WORK_DRIVER,MPR.WORK_CLASS AS WORK_CLASS_ID,'' AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,SUM(ISNULL(RD.SHIPPED_QTY,0)) AS QTY, ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.[CASE],0)) AS [CASE] FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'SO' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = RD.SKU_ID)  AS [CASE], ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.BILLING_PALLET,0)) AS PALLET FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'SO' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = RD.SKU_ID)  AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@ORDERS R ON R.ORDER_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@ORDER_DETAIL RD ON RD.ORDER_ID = R.ORDER_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'SO' AND ISNULL(MPR.WORK_CLASS,'')<>''  AND R.STATUS IN ('Shipped','Closed') ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'OutBound' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER AS WORK_DRIVER,'' AS WORK_CLASS_ID,MPR.FORKLIFT_DRIVER AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,SUM(ISNULL(RD.SHIPPED_QTY,0)) AS QTY, ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.[CASE],0)) AS [CASE] FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'SO' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = RD.SKU_ID)  AS [CASE], ");
            strSql.Append(" (SELECT SUM(ISNULL(IP.BILLING_PALLET,0)) AS PALLET FROM @_@INV_PALLET IP WHERE IP.DOC_ID = MPR.ORDER_ID AND IP.DOC_TYPE = 'SO' AND IP.OWNER_ID = R.OWNER_ID AND IP.SKU_ID = RD.SKU_ID)  AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@ORDERS R ON R.ORDER_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@ORDER_DETAIL RD ON RD.ORDER_ID = R.ORDER_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'SO' AND ISNULL(MPR.FORKLIFT_DRIVER,'')<>'' AND R.STATUS IN ('Shipped','Closed') ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'Movement' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS AS WORK_DRIVER,MPR.WORK_CLASS AS WORK_CLASS_ID,'' AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,SUM(ISNULL(RD.QTY,0)) AS QTY,0 AS [CASE],0 AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT R ON R.MOVEMENT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT_DETAIL RD ON RD.MOVEMENT_ID = R.MOVEMENT_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'MV' AND ISNULL(MPR.WORK_CLASS,'')<>''  AND R.STATUS IN ('Complete','Closed') ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.WORK_CLASS,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT 'Movement' AS DOC_TYPE,MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER AS WORK_DRIVER,'' AS WORK_CLASS_ID,MPR.FORKLIFT_DRIVER AS FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID,SUM(ISNULL(RD.QTY,0)) AS QTY,0 AS [CASE],0 AS [PALLET] ");
            strSql.Append(" FROM @_@MAN_POWER_RESOURCE MPR ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT R ON R.MOVEMENT_ID = MPR.ORDER_ID ");
            strSql.Append(" LEFT JOIN @_@MOVEMENT_DETAIL RD ON RD.MOVEMENT_ID = R.MOVEMENT_ID ");
            strSql.Append(" WHERE MPR.ORDER_TYPE =  'MV' AND ISNULL(MPR.FORKLIFT_DRIVER,'')<>'' AND R.STATUS IN ('Complete','Closed')  ");
            strSql.Append(" GROUP BY MPR.CREATED_DATE,MPR.ORDER_ID,MPR.FORKLIFT_DRIVER,MPR.WORK_TYPE,MPR.IS_HOLIDAY,R.OWNER_ID,RD.SKU_ID ");
            strSql.Append(" ) A ");
            strSql.Append(" LEFT JOIN @_@SKU ON SKU.SKU_ID = A.SKU_ID AND SKU.OWNER_ID = A.OWNER_ID ");
            strSql.Append(" LEFT JOIN ( ");
            strSql.Append(" SELECT DISTINCT SKU.SKU_ID,SKU.OWNER_ID,CGD.START_TIME,CGD.END_TIME,TARIFF.TARIFF_TYPE,CGD.CALENDAR_GROUP_ID,TARIFF.TYPE_CODE,CASE TARIFF.TARIFF_TYPE WHEN 'FIXED' THEN TARIFF.TYPE_CODE ELSE CGD.RATE_ID END AS RATE_ID FROM @_@SKU  ");
            strSql.Append(" LEFT JOIN @_@TARIFF ON SKU.TARIFF_ID = TARIFF.TARIFF_ID ");
            strSql.Append(" LEFT JOIN @_@CALENDAR_GROUP CG ON CG.CALENDAR_GROUP_ID = TARIFF.TYPE_CODE ");
            strSql.Append(" LEFT JOIN @_@CALENDAR_GROUP_DETAIL CGD ON CGD.CALENDAR_GROUP_ID = CG.CALENDAR_GROUP_ID ");
            strSql.Append(" ) B ON B.SKU_ID = A.SKU_ID AND B.OWNER_ID = A.OWNER_ID ");
            strSql.Append(" AND (B.RATE_ID = B.TYPE_CODE OR B.RATE_ID IN (SELECT TOP 1 RATE_ID FROM @_@CALENDAR_GROUP_DETAIL CGD2  WHERE CGD2.CALENDAR_GROUP_ID = B.CALENDAR_GROUP_ID AND ISNULL(CGD2.START_TIME,'1900-01-01') <= A.CREATED_DATE AND ISNULL(CGD2.END_TIME,'9999-01-01') > A.CREATED_DATE ORDER BY ROWID ASC)) ");
            strSql.Append(" LEFT JOIN @_@RATE ON RATE.RATE_ID = B.RATE_ID ");
            strSql.Append(" LEFT JOIN @_@RATE_DETAIL RD ON RD.RATE_ID = RATE.RATE_ID AND RD.RATE_TYPE = A.DOC_TYPE ");
            strSql.Append(" LEFT JOIN @_@EMPLOYEE E ON E.EMPLOYEE_ID = A.WORK_DRIVER ");
            strSql.Append(" LEFT JOIN sysadm.TRANSLATION T ON 'WorkType.'+A.WORK_TYPE = T.ITEM_ID  AND T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE  ");
            strSql.Append(" WHERE A.SKU_ID IS NOT NULL AND QTY > 0 AND RD.DUE_FROM_TO = 'DueTo' AND ISNULL(B.RATE_ID,'') <>'' ");
            strSql.AppendFormat(" {0} ", strWhere);
            strSql.Append(" ) [TEMP] WHERE AMOUNT > 0 GROUP BY WORK_DRIVER,WORK_DRIVER_NAME,WORK_TYPE,WORK_TYPE_D,IS_HOLIDAY,BILLING_TYPE ");
            strSql = strSql.Replace("@_@", whLoginID);
            if (!workClassRptQueryEntity.IsGetAll)
            {
                sql = PagingHelper.GetPagingSQL(strSql.ToString(), workClassRptQueryEntity.CurrentPage, workClassRptQueryEntity.PageSize, workClassRptQueryEntity.SortField, workClassRptQueryEntity.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''").Replace("@USER_ID", "''" + pubParasInfo.UserID + "''");
            }
            else
            {
                sql = strSql.ToString().Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'") + " ORDER BY " + workClassRptQueryEntity.SortField + " " + workClassRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GlobalInventoryWithWHRptDataSet(List<string> sqlWhere, GlobalInventoryWithWHRptQueryEntity globalInventoryWithWHRptQueryEntity, List<string> whLoginID, PubParasInfo pubParasInfo)
        {
            int i;
            string strSqlWhere = string.Empty;
            for (i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    strSqlWhere = strSqlWhere + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    strSqlWhere = strSqlWhere + " AND " + sqlWhere[i].ToString();
                }
            }
            StringBuilder strSelectSql = new StringBuilder();
            strSelectSql.Append(" SELECT WH_ID,OWNER_ID,SKU_ID,SKU_DESCR,SKU_DESCR2,SKU_CLASS_ID,SKU_CLASS_DESCR, SUM(QTY) AS QTY ,UOM,SUM(OK_QTY) AS OK_QTY,SUM(BAD_QTY) AS BAD_QTY,SUM(DAMAGE_QTY) AS DAMAGE_QTY, SUM(HOLD_QTY) AS HOLD_QTY ,SUM(ALLOCATED_QTY) ALLOCATED_QTY,SUM(AVAILABLE_INVENTORY) AS AVAILABLE_INVENTORY,SUM(TOTLE_WGT) AS TOTLE_WGT,SUM(TOTLE_CUBE) AS TOTLE_CUBE,(SELECT MAX(TRANS_DATE) FROM @_@INV_TRANS WHERE LOT=LOT AND TRANS_TYPE+SOURCE_TRANS_TYPE='INRECEIPTDETAILADD') AS INBOUND_DATE, (SELECT MAX(TRANS_DATE) FROM @_@INV_TRANS WHERE LOT=LOT AND TRANS_TYPE='OT') AS OUTBOUND_DATE ");
            if (globalInventoryWithWHRptQueryEntity.SHOW_LOT == "Y")
            {
                strSelectSql.Append(" ,VENDOR_ID,EXTERNAL_LOT,PRODUCE_DATE  ");
            }
            else
            {
                strSelectSql.Append(" ,''AS VENDOR_ID,'' AS EXTERNAL_LOT,'' AS PRODUCE_DATE  ");
            }
            strSelectSql.Append(" FROM ( ");
            for (i = 0; whLoginID.Count > i; i++)
            {
                strSelectSql.Append(" SELECT  F.WH_DB_DESC AS WH_ID,A.OWNER_ID, A.SKU_ID,B.DESCR AS SKU_DESCR,B.DESCR2 AS SKU_DESCR2,B.SKU_CLASS_ID,C.DESCR AS SKU_CLASS_DESCR, SUM(A.QTY) as qty,D.PACK_UOM1 AS UOM, CASE E.LOT_ATTR09+A.STATUS WHEN 'OKOK' THEN SUM(A.QTY) ELSE 0 END AS OK_QTY, CASE E.LOT_ATTR09+A.STATUS WHEN 'HOLDOK' THEN SUM(A.QTY) ELSE 0 END  AS BAD_QTY , CASE E.LOT_ATTR09+A.STATUS WHEN 'DAMAGEOK' THEN SUM(A.QTY) ELSE 0 END AS DAMAGE_QTY,  CASE A.STATUS WHEN 'HOLD' THEN SUM(A.QTY) ELSE 0 END AS HOLD_QTY,SUM(A.ALLOCATED_QTY)AS ALLOCATED_QTY , SUM(CASE A.STATUS WHEN 'HOLD' THEN 0 ELSE CASE CASE E.LOT_ATTR09+A.STATUS WHEN 'OKOK' THEN A.QTY ELSE 0 END WHEN 0 THEN 0 ELSE CASE E.LOT_ATTR09+A.STATUS WHEN 'OKOK' THEN A.QTY ELSE 0 END - A.ALLOCATED_QTY - CASE A.STATUS WHEN 'HOLD' THEN A.QTY ELSE 0 END END END) AS AVAILABLE_INVENTORY, E.VENDOR_ID,E.EXTERNAL_LOT,E.PRODUCE_DATE,SUM(B.GROSS_WGT*A.QTY) AS TOTLE_WGT ,SUM(B.[CUBE]*A.QTY) AS TOTLE_CUBE  ");
                strSelectSql.Append(" FROM @_@INV_LOT_LOC_LPN A   ");
                strSelectSql.Append(" LEFT JOIN @_@SKU B  ON A.OWNER_ID =B.OWNER_ID AND A.SKU_ID = B.SKU_ID   ");
                strSelectSql.Append(" LEFT JOIN @_@SKU_CLASS C ON B.SKU_CLASS_ID=C.SKU_CLASS_ID AND B.OWNER_ID = C.OWNER_ID             ");
                strSelectSql.Append(" LEFT JOIN @_@PACK D ON B.PACK_ID= D.PACK_ID  ");
                strSelectSql.Append(" LEFT JOIN @_@LOT_ATTRIBUTE E ON A.LOT=E.LOT ");
                strSelectSql.Append(" INNER JOIN SYSADM.DB_CONFIG F ON  A.WH_ID = F.DB_LOGIN_ID  AND F.IS_GLOBAL='N' ");
                strSelectSql.AppendFormat(" {0} ", strSqlWhere);
                strSelectSql.Append("  GROUP BY F.WH_DB_DESC,A.LOT,A.OWNER_ID,A.SKU_ID,B.DESCR ,B.DESCR2 ,B.SKU_CLASS_ID,C.DESCR ,D.PACK_UOM1,E.LOT_ATTR09,A.STATUS,E.VENDOR_ID,E.EXTERNAL_LOT,E.PRODUCE_DATE ");
                if (whLoginID.Count > (i + 1))
                {
                    strSelectSql.AppendFormat(" UNION ALL ", new object[0]);
                }
                strSelectSql = strSelectSql.Replace("@_@", whLoginID[i]);
            }
            strSelectSql.Append(" ) temp group by WH_ID,OWNER_ID,SKU_ID,SKU_DESCR,SKU_DESCR2,SKU_CLASS_ID,SKU_CLASS_DESCR,UOM ");
            if (globalInventoryWithWHRptQueryEntity.SHOW_LOT == "Y")
            {
                strSelectSql.Append(" ,VENDOR_ID,EXTERNAL_LOT,PRODUCE_DATE  ");
            }
            string StrSql = strSelectSql.ToString();
            if (!globalInventoryWithWHRptQueryEntity.IsGetAll)
            {
                StrSql = PagingHelper.GetPagingSQL(strSelectSql.ToString(), globalInventoryWithWHRptQueryEntity.CurrentPage, globalInventoryWithWHRptQueryEntity.PageSize, globalInventoryWithWHRptQueryEntity.SortField, globalInventoryWithWHRptQueryEntity.SortDirection);
            }
            else
            {
                StrSql = StrSql + " ORDER BY " + globalInventoryWithWHRptQueryEntity.SortField + " " + globalInventoryWithWHRptQueryEntity.SortDirection;
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, StrSql);
        }

        public int InsertBackupHistoryStock(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, HistoryStockRptQueryEntity historyStockRptQueryEntity, string whLoginID, PubParasInfo pubParasInfo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" INSERT INTO @_@INV_BACK_UP(WH_ID, EXECUTE_DATE, LOT, LOC, LPN_ID, OWNER_ID, SKU_ID,QTY,STATUS,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE) ");
            strSql.Append(" SELECT DISTINCT @WH_ID,@INV_DATE,LOT,LOC,LPN_ID,OWNER_ID,SKU_ID,QTY,'',@USER_ID,GETDATE(),@USER_ID,GETDATE() FROM ( ");
            strSql.Append(" SELECT INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID, P.PACK_UOM1 AS UOM_ID, UOM.UOM_DESCR, ");
            strSql.Append("   SKU.SKU_CLASS_ID, LA.VENDOR_ID, INV.UNIT_PRICE, SKU.SKU_STYLE, PO.CREATED_DATE AS PO_DATE, LAC.DESCR AS SKU_PROPERTY, ");
            strSql.Append("   LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
            strSql.Append("   LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE,  ");
            strSql.Append("   SUM(INV.QTY) AS QTY, SUM(INV.QTY) * SKU.GROSS_WGT AS GROSS_WGT, SUM(INV.QTY) * SKU.[CUBE] AS [CUBE] ");
            strSql.Append(" FROM ( ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ReceiptReversal' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PutawayMove' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'AdjustmentDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'Picking' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'PickingUpdate' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ShipmentReversal' AND it.STATUS = 'OK' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailAdd' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, it.QTY ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'TransferDetailUpdate' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.FROM_LOC AS LOC, it.FROM_LPN_ID AS LPN_ID, - ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" UNION ALL ");
            strSql.Append(" SELECT it.OWNER_ID, it.SKU_ID, it.LOT, it.VENDOR_ID, it.UNIT_PRICE, ");
            strSql.Append("   it.TO_LOC AS LOC, it.TO_LPN_ID AS LPN_ID, ABS(it.QTY) ");
            strSql.Append(" FROM @_@INV_TRANS it ");
            strSql.Append(" WHERE it.SOURCE_TRANS_TYPE = 'ConsoleMove' AND it.TRANS_DATE < @TRANS_DATE ");
            strSql.Append(" ) INV LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = INV.OWNER_ID AND SKU.SKU_ID = INV.SKU_ID ");
            strSql.Append("   LEFT JOIN @_@SKU_CLASS SC ON SC.OWNER_ID = SKU.OWNER_ID AND SC.SKU_CLASS_ID = SKU.SKU_CLASS_ID ");
            strSql.Append("   LEFT JOIN @_@PACK P ON P.PACK_ID = SKU.PACK_ID");
            strSql.Append("   LEFT JOIN @_@UOM UOM ON UOM.UOM_ID = P.PACK_UOM1");
            strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.OWNER_ID = INV.OWNER_ID AND LA.SKU_ID = INV.SKU_ID AND LA.LOT = INV.LOT ");
            strSql.Append("   LEFT JOIN @_@LOT_ATTRIBUTE_CODE LAC ON LA.LOT_ATTR09 = LAC.CODE_ID AND LAC.GROUP_ID = '货品属性' ");
            strSql.Append("   LEFT JOIN @_@RECEIPT RECEIPT ON RECEIPT.RECEIPT_ID = LA.LOT_ATTR10 ");
            strSql.Append("   LEFT JOIN @_@PURCHASE_ORDER PO ON PO.PO_ID = RECEIPT.PO_ID ");
            strSql.Append(" WHERE 1 = 1 ");
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                strSql.Append(" AND " + sqlWhere[i].ToString());
            }
            strSql.Append(" GROUP BY INV.OWNER_ID, INV.SKU_ID, SKU.DESCR, INV.LOC, INV.LOT, INV.LPN_ID, SKU.PACK_ID, P.PACK_UOM1, UOM.UOM_DESCR, ");
            strSql.Append("   SKU.SKU_CLASS_ID, LA.VENDOR_ID, INV.UNIT_PRICE, SKU.SKU_STYLE, SKU.GROSS_WGT, SKU.NET_WGT, SKU.[CUBE], PO.CREATED_DATE, LAC.DESCR,  ");
            strSql.Append("   LA.LOT_ATTR01, LA.LOT_ATTR02, LA.LOT_ATTR03, LA.LOT_ATTR04, LA.LOT_ATTR05, LA.LOT_ATTR06, LA.LOT_ATTR07, LA.LOT_ATTR08, LA.LOT_ATTR09, LA.LOT_ATTR10, ");
            strSql.Append("   LA.PRODUCE_DATE, LA.[EXPIRY_DATE], LA.EXTERNAL_LOT, LA.RECEIPT_DATE ");
            strSql.Append(" HAVING SUM(INV.QTY) <> 0 ");
            strSql.Append(" ) TEMP");
            string sql = strSql.ToString().Replace("@_@", whLoginID).Replace("@TRANS_DATE", "'" + historyStockRptQueryEntity.INV_DATE + "'").Replace("@INV_DATE", "'" + historyStockRptQueryEntity.INV_DATE + "'").Replace("@USER_ID", "'" + pubParasInfo.UserID + "'").Replace("@WH_ID", "'" + whLoginID.Substring(0, whLoginID.Length - 1) + "'");
            return dataBase.ExecuteNonQuery(tran, CommandType.Text, sql);
        }
    }
}

